2
0

Refactor for safety.

This commit is contained in:
Maarten Billemont 2019-10-05 16:33:34 -04:00
parent 44fa32697a
commit 2af71fbc34
3 changed files with 6 additions and 4 deletions

View File

@ -201,6 +201,7 @@ void mpw_set_json_data(
continue;
}
*(child = &data->children[data->children_count - 1]) = (MPMarshalledData){ .obj_key = mpw_strdup( entry.key ) };
mpw_marshal_data_set_null( child, NULL );
}
mpw_set_json_data( child, entry.val );
@ -221,6 +222,7 @@ void mpw_set_json_data(
continue;
}
*(child = &data->children[data->children_count - 1]) = (MPMarshalledData){ .arr_index = index };
mpw_marshal_data_set_null( child, NULL );
}
mpw_set_json_data( child, json_object_array_get_idx( obj, index ) );

View File

@ -112,7 +112,7 @@ MPMarshalledFile *mpw_marshal_file(
if (!(file = malloc( sizeof( MPMarshalledFile ) )))
return NULL;
*file = (MPMarshalledFile){};
*file = (MPMarshalledFile){ .info = NULL, .data = NULL, .error = (MPMarshalError){ .type = MPMarshalSuccess, .message = NULL } };
}
if (data && data != file->data) {
@ -986,8 +986,8 @@ MPMarshalledUser *mpw_marshal_auth(
// Section: "user"
bool fileRedacted = mpw_marshal_data_get_bool( file->data, "export", "redacted", NULL )
|| mpw_marshal_data_is_null( file->data, "export", "redacted", NULL );
MPAlgorithmVersion
algorithm = mpw_default_n( MPAlgorithmVersionCurrent, mpw_marshal_data_get_num( file->data, "user", "algorithm", NULL ) );
MPAlgorithmVersion algorithm =
mpw_default_n( MPAlgorithmVersionCurrent, mpw_marshal_data_get_num( file->data, "user", "algorithm", NULL ) );
if (algorithm < MPAlgorithmVersionFirst || algorithm > MPAlgorithmVersionLast) {
file->error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user algorithm: %u", algorithm ) };
return NULL;

View File

@ -29,7 +29,7 @@ MP_LIBS_END
//// Types.
#define mpw_default( __default, __value ) ({ __typeof__ (__default) _v = (__typeof__ (__default))(__value); _v = _v? _v: __default; })
#define mpw_default_n( __default, __num ) ({ __typeof__ (__default) _n = (__typeof__ (__default))(__num); _n = !isnan( _n )? _n: __default; })
#define mpw_default_n( __default, __num ) ({ __typeof__ (__num) _n = (__num); !isnan( _n )? (__typeof__ (__default))_n: __default; })
typedef mpw_enum( unsigned int, MPMarshalFormat ) {
/** Do not marshal. */