This update tweaks the SELECT function, at the point commented
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Feb 2009 01:43:25 +0000 (01:43 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Feb 2009 01:43:25 +0000 (01:43 +0000)
"make sure the target relation is in the join tree".

The new logic should be equivalent to the old, except that
the old code potentially invokes undefined behavior by
reading through a null pointer.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@12054 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/c-apps/oils_cstore.c

index 13a455a..1b5789c 100644 (file)
@@ -2326,7 +2326,6 @@ static char* SELECT (
        jsonObject* selfield = NULL;
        jsonObject* snode = NULL;
        jsonObject* onode = NULL;
-       jsonObject* found = NULL;
 
        char* string = NULL;
        int from_function = 0;
@@ -2439,20 +2438,20 @@ static char* SELECT (
                    if (strcmp(core_class,cname)) {
                            if (!join_hash) continue;
 
-                           if (join_hash->type == JSON_STRING) {
+                               unsigned long size;
+
+                               if (join_hash->type == JSON_STRING) {
                                    string = jsonObjectToSimpleString(join_hash);
-                                   found = strcmp(string,cname) ? NULL : jsonParseString("{\"1\":\"1\"}");
+                                       size = strcmp( string, cname ) ? 0 : 1;
                                    free(string);
                            } else {
-                                   found = jsonObjectFindPath(join_hash, "//%s", cname);
+                                   jsonObject* found = jsonObjectFindPath(join_hash, "//%s", cname);
+                                       size = found->size;
+                                       jsonObjectFree( found );
                            }
 
-                           if (!found->size) {
-                                   jsonObjectFree(found);
+                           if ( 0 == size )
                                    continue;
-                           }
-
-                           jsonObjectFree(found);
                    }
 
                    // stitch together the column list ...