diff options
author | Thomas White <taw@physics.org> | 2019-01-30 17:05:32 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-01-30 17:05:32 +0100 |
commit | 24b41117f5e0365f316f9b2decd7a52a0766b9d0 (patch) | |
tree | 0b3e6023342f9775973f62d138ed1fd04c859218 /libcrystfel | |
parent | 52a25ae71793d63252a16f75085ace22eda76717 (diff) |
Make sure of string length in get_event_string()
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/events.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c index 2bf6cfad..7cd05784 100644 --- a/libcrystfel/src/events.c +++ b/libcrystfel/src/events.c @@ -297,13 +297,13 @@ char *get_event_string(struct event *ev) if ( ev == NULL ) return strdup("(none)"); - ev_len = 0; + ev_len = 1; /* Zero terminator */ for ( i=0; i<ev->path_length; i++ ) { ev_len += strlen(ev->path_entries[i]); - ev_len += 1; + ev_len += 1; /* Slash afterwards */ } - ev_len += 16*ev->dim_length; - ev_len += 2; + ev_len += 16*ev->dim_length; /* Max length of number plus slash */ + ev_len += 2; /* Double slash in middle */ evstr = malloc(ev_len); if ( evstr == NULL ) return NULL; @@ -318,7 +318,7 @@ char *get_event_string(struct event *ev) for ( i=0; i<ev->dim_length; i++ ) { char num_buf[16]; - sprintf(num_buf, "%i", ev->dim_entries[i]); + snprintf(num_buf, 16, "%i", ev->dim_entries[i]); if ( i > 0 ) strcat(evstr, "/"); strcat(evstr, num_buf); } |