Revision: 65162
          http://sourceforge.net/p/brlcad/code/65162
Author:   brlcad
Date:     2015-06-03 06:23:25 +0000 (Wed, 03 Jun 2015)
Log Message:
-----------
it's possible for bu_fgets to return an empty string, so make sure we don't try 
to index -1

Modified Paths:
--------------
    brlcad/trunk/src/libbu/vls.c

Modified: brlcad/trunk/src/libbu/vls.c
===================================================================
--- brlcad/trunk/src/libbu/vls.c        2015-06-03 06:13:43 UTC (rev 65161)
+++ brlcad/trunk/src/libbu/vls.c        2015-06-03 06:23:25 UTC (rev 65162)
@@ -631,25 +631,33 @@
     startlen = bu_vls_strlen(vp);
 
     do {
+       size_t buflen;
+
        bufp = bu_fgets(buffer, BUFSIZ+1, fp);
 
        if (!bufp)
            return -1;
 
+       /* an empty parse means we're done */
+       buflen = strlen(bufp);
+       if (buflen == 0) {
+           break;
+       }
+
        /* keep reading if we just filled the buffer */
-       if ((strlen(bufp) == BUFSIZ) && (bufp[BUFSIZ-1] != '\n') && 
(bufp[BUFSIZ-1] != '\r')) {
+       if ((buflen == BUFSIZ) && (bufp[BUFSIZ-1] != '\n') && (bufp[BUFSIZ-1] 
!= '\r')) {
            done = 0;
        } else {
            done = 1;
        }
 
        /* strip the trailing EOL (or at least part of it) */
-       if ((bufp[strlen(bufp)-1] == '\n') || (bufp[strlen(bufp)-1] == '\r'))
-           bufp[strlen(bufp)-1] = '\0';
+       if ((bufp[buflen-1] == '\n') || (bufp[buflen-1] == '\r'))
+           bufp[buflen-1] = '\0';
 
        /* handle \r\n lines */
-       if (bufp[strlen(bufp)-1] == '\r')
-           bufp[strlen(bufp)-1] = '\0';
+       if (bufp[buflen-1] == '\r')
+           bufp[buflen-1] = '\0';
 
        bu_vls_printf(vp, "%s", bufp);
     } while (!done);

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