Permalink
Browse files

Fix for a string length bug

  • Loading branch information...
1 parent 2e05334 commit bdc2478ce56aaf289928744ca9112a9e31b0a043 @toddtreece committed Oct 28, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 io.c
View
17 io.c
@@ -55,9 +55,12 @@ long long mongodb_save(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned
if (args->args[i]) {
if (args->arg_type[i] == STRING_RESULT || args->arg_type[i] == DECIMAL_RESULT) {
+
+ if(args->lengths[i] < strlen(args->args[i])) {
- //args array is not null terminated by default
- args->args[i][args->lengths[i]] = '\0';
+ args->args[i][args->lengths[i]] = '\0';
+
+ }
if(strcmp(args->args[i], "NULL") == 0 || args->lengths[i] == 0) {
@@ -77,8 +80,16 @@ long long mongodb_save(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned
} else if (args->arg_type[i] == INT_RESULT) {
- bson_append_int(b, args->attributes[i],*((long long*) args->args[i]));
+ if(args->args[i] == NULL) {
+
+ bson_append_null(b, args->attributes[i]);
+
+ } else {
+
+ bson_append_int(b, args->attributes[i],*((long long*) args->args[i]));
+ }
+
}
}

0 comments on commit bdc2478

Please sign in to comment.