Revision: 75411
          http://sourceforge.net/p/brlcad/code/75411
Author:   brlcad
Date:     2020-04-15 19:13:25 +0000 (Wed, 15 Apr 2020)
Log Message:
-----------
it doesn't like strncpy because of off-by-one errors, which consequently was 
introduced by converting this to bu_strlcpy.  strlcpy guarantees 
nul-termination and just takes the size of the buffer being written into.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/tests/dylib/plugin_1.cpp
    brlcad/trunk/src/libbu/tests/dylib/plugin_2.cpp

Modified: brlcad/trunk/src/libbu/tests/dylib/plugin_1.cpp
===================================================================
--- brlcad/trunk/src/libbu/tests/dylib/plugin_1.cpp     2020-04-15 18:41:12 UTC 
(rev 75410)
+++ brlcad/trunk/src/libbu/tests/dylib/plugin_1.cpp     2020-04-15 19:13:25 UTC 
(rev 75411)
@@ -31,15 +31,12 @@
     std::string sout = std::to_string(output);
 
     if (sout.length() > (size_t)(rlen - 1)) {
-       // We'll copy what we can, but we don't have enough room for
-       // everything.
+       // copy what we can, but don't have room for everything.
        ret = 1;
     }
 
-    // Copy the result in to the provided buffer and null terminate
-    bu_strlcpy((*result), sout.c_str(), rlen - 1);
-    size_t npos = ((size_t)rlen < sout.length()) ? rlen - 1 : sout.length();
-    (*result)[npos] = '\0';
+    // Copy result into the provided buffer with guaranteed nul-termination
+    bu_strlcpy((*result), sout.c_str(), rlen);
 
     return ret;
 }

Modified: brlcad/trunk/src/libbu/tests/dylib/plugin_2.cpp
===================================================================
--- brlcad/trunk/src/libbu/tests/dylib/plugin_2.cpp     2020-04-15 18:41:12 UTC 
(rev 75410)
+++ brlcad/trunk/src/libbu/tests/dylib/plugin_2.cpp     2020-04-15 19:13:25 UTC 
(rev 75411)
@@ -31,15 +31,12 @@
     std::string sout = std::to_string(output);
 
     if (sout.length() > (size_t)(rlen - 1)) {
-       // We'll copy what we can, but we don't have enough room for
-       // everything.
+       // copy what we can, but don't have room for everything.
        ret = 1;
     }
 
-    // Copy the result in to the provided buffer and null terminate
-    bu_strlcpy((*result), sout.c_str(), rlen - 1);
-    size_t npos = ((size_t)rlen < sout.length()) ? rlen - 1 : sout.length();
-    (*result)[npos] = '\0';
+    // Copy result into the provided buffer with guaranteed nul-termination
+    bu_strlcpy((*result), sout.c_str(), rlen);
 
     return ret;
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to