Refactor for safety.
This commit is contained in:
parent
44fa32697a
commit
2af71fbc34
@ -201,6 +201,7 @@ void mpw_set_json_data(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*(child = &data->children[data->children_count - 1]) = (MPMarshalledData){ .obj_key = mpw_strdup( entry.key ) };
|
*(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 );
|
mpw_set_json_data( child, entry.val );
|
||||||
@ -221,6 +222,7 @@ void mpw_set_json_data(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*(child = &data->children[data->children_count - 1]) = (MPMarshalledData){ .arr_index = index };
|
*(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 ) );
|
mpw_set_json_data( child, json_object_array_get_idx( obj, index ) );
|
||||||
|
@ -112,7 +112,7 @@ MPMarshalledFile *mpw_marshal_file(
|
|||||||
if (!(file = malloc( sizeof( MPMarshalledFile ) )))
|
if (!(file = malloc( sizeof( MPMarshalledFile ) )))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*file = (MPMarshalledFile){};
|
*file = (MPMarshalledFile){ .info = NULL, .data = NULL, .error = (MPMarshalError){ .type = MPMarshalSuccess, .message = NULL } };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data && data != file->data) {
|
if (data && data != file->data) {
|
||||||
@ -986,8 +986,8 @@ MPMarshalledUser *mpw_marshal_auth(
|
|||||||
// Section: "user"
|
// Section: "user"
|
||||||
bool fileRedacted = mpw_marshal_data_get_bool( file->data, "export", "redacted", NULL )
|
bool fileRedacted = mpw_marshal_data_get_bool( file->data, "export", "redacted", NULL )
|
||||||
|| mpw_marshal_data_is_null( file->data, "export", "redacted", NULL );
|
|| mpw_marshal_data_is_null( file->data, "export", "redacted", NULL );
|
||||||
MPAlgorithmVersion
|
MPAlgorithmVersion algorithm =
|
||||||
algorithm = mpw_default_n( MPAlgorithmVersionCurrent, mpw_marshal_data_get_num( file->data, "user", "algorithm", NULL ) );
|
mpw_default_n( MPAlgorithmVersionCurrent, mpw_marshal_data_get_num( file->data, "user", "algorithm", NULL ) );
|
||||||
if (algorithm < MPAlgorithmVersionFirst || algorithm > MPAlgorithmVersionLast) {
|
if (algorithm < MPAlgorithmVersionFirst || algorithm > MPAlgorithmVersionLast) {
|
||||||
file->error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user algorithm: %u", algorithm ) };
|
file->error = (MPMarshalError){ MPMarshalErrorIllegal, mpw_str( "Invalid user algorithm: %u", algorithm ) };
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -29,7 +29,7 @@ MP_LIBS_END
|
|||||||
//// Types.
|
//// Types.
|
||||||
|
|
||||||
#define mpw_default( __default, __value ) ({ __typeof__ (__default) _v = (__typeof__ (__default))(__value); _v = _v? _v: __default; })
|
#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 ) {
|
typedef mpw_enum( unsigned int, MPMarshalFormat ) {
|
||||||
/** Do not marshal. */
|
/** Do not marshal. */
|
||||||
|
Loading…
Reference in New Issue
Block a user