[brlcad-commits] SF.net SVN: brlcad: [30830] brlcad/trunk/src/libbu/str.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2008-04-26 16:07:18
|
Revision: 30830 http://brlcad.svn.sourceforge.net/brlcad/?rev=30830&view=rev Author: brlcad Date: 2008-04-26 09:07:24 -0700 (Sat, 26 Apr 2008) Log Message: ----------- only warn about the string truncation if debug is turned as it is indeed entirely valid for the src string in strlcpy to be longer than size. this check was mainly added because there was a slew of strncpy code migrated over and the truncation by the new strlcpy wasn't intentional (or desirable). there are undoubtedly more callers that need to be weeded out. Modified Paths: -------------- brlcad/trunk/src/libbu/str.c Modified: brlcad/trunk/src/libbu/str.c =================================================================== --- brlcad/trunk/src/libbu/str.c 2008-04-26 14:40:35 UTC (rev 30829) +++ brlcad/trunk/src/libbu/str.c 2008-04-26 16:07:24 UTC (rev 30830) @@ -67,6 +67,7 @@ dstsize = strlen(dst); srcsize = strlen(src); + if (dstsize == size - 1) { bu_semaphore_acquire(BU_SEM_SYSCALL); fprintf(stderr, "WARNING: [%s] concatenation string is already full at %ld chars\n", label, size-1); @@ -77,9 +78,11 @@ fprintf(stderr, "WARNING: [%s] concatenation string is already full, exceeds size (%ld > %ld)\n", label, dstsize, size-1); bu_semaphore_release(BU_SEM_SYSCALL); } else if (srcsize >= size - dstsize) { - bu_semaphore_acquire(BU_SEM_SYSCALL); - fprintf(stderr, "WARNING: [%s] string truncation, exceeding %ld char max concatenating %ld chars (started with %ld)\n", label, size-1, srcsize, dstsize); - bu_semaphore_release(BU_SEM_SYSCALL); + if (bu_debug) { + bu_semaphore_acquire(BU_SEM_SYSCALL); + fprintf(stderr, "WARNING: [%s] string truncation, exceeding %ld char max concatenating %ld chars (started with %ld)\n", label, size-1, srcsize, dstsize); + bu_semaphore_release(BU_SEM_SYSCALL); + } } #ifdef HAVE_STRLCAT @@ -128,10 +131,13 @@ } srcsize = strlen(src); - if (srcsize >= size ) { - bu_semaphore_acquire(BU_SEM_SYSCALL); - fprintf(stderr, "WARNING: [%s] string truncation, exceeding %ld char max copying %ld chars\n", label, size-1, srcsize); - bu_semaphore_release(BU_SEM_SYSCALL); + + if (bu_debug) { + if (srcsize >= size ) { + bu_semaphore_acquire(BU_SEM_SYSCALL); + fprintf(stderr, "WARNING: [%s] string truncation, exceeding %ld char max copying %ld chars\n", label, size-1, srcsize); + bu_semaphore_release(BU_SEM_SYSCALL); + } } #ifdef HAVE_STRLCPY This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |