[Opensrf-commits] r1322 - trunk/src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu May 15 16:55:06 EDT 2008
Author: erickson
Date: 2008-05-15 16:55:02 -0400 (Thu, 15 May 2008)
New Revision: 1322
Modified:
trunk/src/libopensrf/osrf_legacy_json.c
Log:
Patch from Scott McKellar:
This patch tweaks a few things.
1. In json_parse_json_string() we declare a character array buff[],
fill it with nuls, and never refer to it again. I eliminated it.
2. A few lines below that, we use memset() to clear a three-character
buffer. I replaced the memset() with an initializer clause.
3. in json_handle_error() we were relying on the osrf_clearbuf macro
to add a terminal nul. However the plan is for this macro to become
a no-op someday. I added the nul manually.
Modified: trunk/src/libopensrf/osrf_legacy_json.c
===================================================================
--- trunk/src/libopensrf/osrf_legacy_json.c 2008-05-15 20:46:15 UTC (rev 1321)
+++ trunk/src/libopensrf/osrf_legacy_json.c 2008-05-15 20:55:02 UTC (rev 1322)
@@ -478,17 +478,11 @@
return json_handle_error(string, index,
"json_parse_json_string(): truncated escaped unicode"); }
- char buff[5];
- osrf_clearbuf(buff, sizeof(buff));
- memcpy(buff, string + (*index), 4);
-
-
/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
/* The following chunk was borrowed with permission from
json-c http://oss.metaparadigm.com/json-c/ */
- unsigned char utf_out[3];
- memset(utf_out, 0, sizeof(utf_out));
+ unsigned char utf_out[3] = { '\0', '\0', '\0' };
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
@@ -695,10 +689,12 @@
osrf_clearbuf(buf, sizeof(buf));
if(*index > 30)
- strncpy( buf, string + (*index - 30), 59 );
+ strncpy( buf, string + (*index - 30), sizeof(buf) - 1 );
else
- strncpy( buf, string, 59 );
+ strncpy( buf, string, sizeof(buf) - 1 );
+ buf[ sizeof(buf) - 1 ] = '\0';
+
fprintf(stderr,
"\nError parsing json string at charracter %c "
"(code %d) and index %ld\nString length: %d\nMsg:\t%s\nNear:\t%s\nFull String:\t%s\n",
More information about the opensrf-commits
mailing list