Skip to content

Commit

Permalink
More precise emit_int error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
  • Loading branch information
emersonknapp committed Feb 15, 2023
1 parent 3fd2d31 commit d5cae44
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rcl/src/rcl/type_version_hash.c
Expand Up @@ -71,10 +71,15 @@ static int emit_key(yaml_emitter_t * emitter, const char * key)

static int emit_int(yaml_emitter_t * emitter, size_t val, const char * fmt)
{
// longest uint64 is 21 decimal digits
// longest uint64 is 20 decimal digits, plus one byte for trailing \0
char decimal_buf[21];
yaml_event_t event;
if ((size_t)snprintf(decimal_buf, sizeof(decimal_buf), fmt, val) >= sizeof(decimal_buf)) {
int ret = snprintf(decimal_buf, sizeof(decimal_buf), fmt, val);
if (ret < 0) {
emitter->problem = "Failed expanding integer";
return 0;
}
if ((size_t)ret >= sizeof(decimal_buf)) {
emitter->problem = "Decimal buffer overflow";
return 0;
}
Expand Down

0 comments on commit d5cae44

Please sign in to comment.