Revision: 49325
http://brlcad.svn.sourceforge.net/brlcad/?rev=49325&view=rev
Author: brlcad
Date: 2012-02-08 07:43:45 +0000 (Wed, 08 Feb 2012)
Log Message:
-----------
replace call to strncpy() with call to bu_vls_strncpy(). simplifies the code
some since we can just let the bu func do the nul-termination and heap copy for
us.
Modified Paths:
--------------
brlcad/trunk/src/libbu/parse.c
Modified: brlcad/trunk/src/libbu/parse.c
===================================================================
--- brlcad/trunk/src/libbu/parse.c 2012-02-08 07:33:23 UTC (rev 49324)
+++ brlcad/trunk/src/libbu/parse.c 2012-02-08 07:43:45 UTC (rev 49325)
@@ -536,7 +536,7 @@
int dot_seen;
const char *numstart;
double tmp_double;
- char buf[128];
+ struct bu_vls buf = BU_VLS_INIT_ZERO;
int len;
for (i=0; i < count && *str; ++i) {
@@ -571,13 +571,12 @@
}
len = str - numstart;
- if ((size_t)len > sizeof(buf)-1)
- len = sizeof(buf)-1;
- strncpy(buf, numstart, len);
- buf[len] = '\0';
+ bu_vls_strncpy(&buf, numstart, len);
- if (UNLIKELY(sscanf(buf, "%lf", &tmp_double) != 1))
+ if (UNLIKELY(sscanf(bu_vls_addr(&buf), "%lf", &tmp_double) != 1)) {
+ bu_vls_free(&buf);
return -1;
+ }
*loc++ = tmp_double;
@@ -593,6 +592,8 @@
while (*str && isspace(*str))
str++;
}
+
+ bu_vls_free(&buf);
return 0;
}
@@ -1842,8 +1843,10 @@
const char *prev=NULL;
const char *start=NULL;
const char *end=NULL;
- char *out=NULL;
+ struct bu_vls out = BU_VLS_INIT_ZERO;
+ char *ret = NULL;
+
while (*ptr) {
/* skip leading white space */
while (*ptr && isspace(*ptr)) {
@@ -1913,11 +1916,12 @@
}
len = end - start + 1;
- out = (char *)bu_malloc(len+1, "parse_list_elem:out");
- strncpy(out, start, len);
- *(out + len) = '\0';
+ bu_vls_strncpy(&out, start, len);
- return out;
+ ret = bu_vls_strdup(&out);
+ bu_vls_free(&out);
+
+ return ret;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits