Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CDRIVER-190 Check overflow - fix build
  • Loading branch information
gjmurakami-10gen committed Jan 16, 2013
1 parent 6396e9d commit af3f910
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 62 deletions.
6 changes: 3 additions & 3 deletions SConstruct
Expand Up @@ -24,7 +24,7 @@ AddOption('--seed-start-port',


AddOption('--c99', AddOption('--c99',
dest='use_c99', dest='use_c99',
default=False, default=True,
action='store_true', action='store_true',
help='Compile with c99 (recommended for gcc)') help='Compile with c99 (recommended for gcc)')


Expand Down Expand Up @@ -100,8 +100,8 @@ if os.sys.platform in ["darwin", "linux2"]:
env.Append( CPPFLAGS="-pedantic -Wall -ggdb -DMONGO_HAVE_STDINT" ) env.Append( CPPFLAGS="-pedantic -Wall -ggdb -DMONGO_HAVE_STDINT" )
if not GetOption('standard_env'): if not GetOption('standard_env'):
env.Append( CPPFLAGS=" -D_POSIX_SOURCE -D_DARWIN_C_SOURCE" ) env.Append( CPPFLAGS=" -D_POSIX_SOURCE -D_DARWIN_C_SOURCE" )
env.Append( CPPPATH=["/opt/local/include/"] ) #env.Append( CPPPATH=["/opt/local/include/"] )
env.Append( LIBPATH=["/opt/local/lib/"] ) #env.Append( LIBPATH=["/opt/local/lib/"] )


if GetOption('use_c99'): if GetOption('use_c99'):
env.Append( CFLAGS=" -std=c99 " ) env.Append( CFLAGS=" -std=c99 " )
Expand Down
54 changes: 0 additions & 54 deletions src/bcon.c
Expand Up @@ -34,12 +34,6 @@ char *bcon_errstr[] = {
"bson finish error" "bson finish error"
}; };


static int bcon_error(bson *b, const bcon *bc, size_t i, bcon_error_t err) {
b->err = err;
b->errstr = bcon_errstr[err];
return BCON_ERROR;
}

bcon_error_t bson_append_bcon_array(bson *b, const bcon *bc); bcon_error_t bson_append_bcon_array(bson *b, const bcon *bc);


/* should be static, but it used by test files */ /* should be static, but it used by test files */
Expand Down Expand Up @@ -376,51 +370,3 @@ void bcon_print(const bcon *bc) { /* prints internal representation, not JSON */
} }
putchar('}'); putchar('}');
} }

/* TODO - incomplete */
static void bcon_json_print(bcon *bc, int n) {
int t = 0;
int key_value_count = 0;
char *s;
int end_of_data;
bcon *bcp;
putchar('{');
for (end_of_data = 0, bcp = bc; !end_of_data; bcp++) {
bcon bci = *bcp;
switch (t) {
case 'l':
if (key_value_count & 0x1) putchar(':');
printf("%ld", bci.l);
t = 0;
key_value_count++;
break;
case 's': /* fall through */
default:
s = bci.s;
switch (*s) {
case ':':
++s;
t = *++s;
break;
case '{':
if (key_value_count & 0x1) putchar(':');
putchar(*s);
key_value_count = 0;
break;
case '}':
putchar(*s);
key_value_count = 2;
break;
default:
if (key_value_count & 0x1) putchar(':');
else if (key_value_count > 1) putchar(',');
printf("\"%s\"", s);
t = 0;
key_value_count++;
break;
}
break;
}
}
putchar('}');
}
6 changes: 3 additions & 3 deletions src/bson.c
Expand Up @@ -758,7 +758,7 @@ static int bson_append_string_base( bson *b, const char *name,
size_t sl = len + 1; size_t sl = len + 1;
if ( sl > INT32_MAX ) { if ( sl > INT32_MAX ) {
b->err = BSON_SIZE_OVERFLOW; b->err = BSON_SIZE_OVERFLOW;
// string too long /* string too long */
return BSON_ERROR; return BSON_ERROR;
} }
if ( bson_check_string( b, ( const char * )value, sl - 1 ) == BSON_ERROR ) if ( bson_check_string( b, ( const char * )value, sl - 1 ) == BSON_ERROR )
Expand Down Expand Up @@ -802,11 +802,11 @@ MONGO_EXPORT int bson_append_code_w_scope_n( bson *b, const char *name,
size_t sl, size; size_t sl, size;
if ( !scope ) return BSON_ERROR; if ( !scope ) return BSON_ERROR;
sl = len + 1; sl = len + 1;
if ( 4 + 4 + (long long)sl + (long long)bson_size( scope ) > (long long)INT32_MAX ) { size = 4 + 4 + sl + bson_size( scope );
if ( size > (size_t)INT32_MAX ) {
b->err = BSON_SIZE_OVERFLOW; b->err = BSON_SIZE_OVERFLOW;
return BSON_ERROR; return BSON_ERROR;
} }
size = 4 + 4 + sl + bson_size( scope );
if ( bson_append_estart( b, BSON_CODEWSCOPE, name, size ) == BSON_ERROR ) if ( bson_append_estart( b, BSON_CODEWSCOPE, name, size ) == BSON_ERROR )
return BSON_ERROR; return BSON_ERROR;
bson_append32_as_int( b, ( int )size ); bson_append32_as_int( b, ( int )size );
Expand Down
3 changes: 2 additions & 1 deletion src/mongo.c
Expand Up @@ -1411,6 +1411,7 @@ MONGO_EXPORT int mongo_cursor_next( mongo_cursor *cursor ) {


MONGO_EXPORT int mongo_cursor_destroy( mongo_cursor *cursor ) { MONGO_EXPORT int mongo_cursor_destroy( mongo_cursor *cursor ) {
int result = MONGO_OK; int result = MONGO_OK;
char *data;


if ( !cursor ) return result; if ( !cursor ) return result;


Expand All @@ -1425,7 +1426,7 @@ MONGO_EXPORT int mongo_cursor_destroy( mongo_cursor *cursor ) {
if( mm == NULL ) { if( mm == NULL ) {
return MONGO_ERROR; return MONGO_ERROR;
} }
char *data = &mm->data; data = &mm->data;
data = mongo_data_append32( data, &ZERO ); data = mongo_data_append32( data, &ZERO );
data = mongo_data_append32( data, &ONE ); data = mongo_data_append32( data, &ONE );
mongo_data_append64( data, &cursor->reply->fields.cursorID ); mongo_data_append64( data, &cursor->reply->fields.cursorID );
Expand Down
2 changes: 1 addition & 1 deletion test/write_concern_test.c
Expand Up @@ -36,7 +36,7 @@ void bson_dump( bson * b ) {
printf("\tstack: {"); printf("\tstack: {");
delim = ""; delim = "";
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
printf("%s%d", delim, b->stack[i]); printf("%s%zd", delim, b->stack[i]);
delim = ","; delim = ",";
} }
printf("},\n"); printf("},\n");
Expand Down

0 comments on commit af3f910

Please sign in to comment.