Patch from Scott McKellar:
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 15 May 2008 20:55:02 +0000 (20:55 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 15 May 2008 20:55:02 +0000 (20:55 +0000)
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.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1322 9efc2488-bf62-4759-914b-345cdb29e865

src/libopensrf/osrf_legacy_json.c

index 40215d5..17dab25 100644 (file)
@@ -478,17 +478,11 @@ int json_parse_json_string(char* string, unsigned long* index, jsonObject* obj,
                                                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,9 +689,11 @@ int json_handle_error(char* string, unsigned long* index, char* err_msg) {
        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 "