From 1d19dc46909a19ba4ad2a934ffd786b284ecdce2 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 21 Mar 2024 19:35:45 +0000 Subject: [PATCH] save: Avoid call to sign pad before checking data read error This doesn't change behaviour; it still returns `CYAML_ERR_INVALID_DATA_SIZE` if the schema's `data_size` is invalid. Closes #228 --- src/save.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/save.c b/src/save.c index 95f1b43..dc84ac8 100644 --- a/src/save.c +++ b/src/save.c @@ -639,16 +639,18 @@ static cyaml_err_t cyaml__write_int( { cyaml_err_t err; int64_t number; + uint64_t raw; - number = cyaml_sign_pad( - cyaml_data_read(schema->data_size, data, &err), - schema->data_size); - if (err == CYAML_OK) { - const char *string = cyaml__get_int(number); - err = cyaml__emit_scalar(ctx, schema, string, YAML_INT_TAG); + raw = cyaml_data_read(schema->data_size, data, &err); + if (err != CYAML_OK) { + return err; } - return err; + number = cyaml_sign_pad(raw, schema->data_size); + + return cyaml__emit_scalar(ctx, schema, + cyaml__get_int(number), + YAML_INT_TAG); } /**