Skip to content

Commit

Permalink
Replace sprintf with snprintf
Browse files Browse the repository at this point in the history
Fixes #292
  • Loading branch information
evanmiller committed Jan 16, 2023
1 parent fc78c23 commit 75dce86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/spss/readstat_por.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ssize_t por_utf8_encode(const unsigned char *input, size_t input_len,
}
/* TODO - For some reason that replacement character isn't recognized
* by some systems, so be prepared to insert an ASCII space instead */
int printed = sprintf(output + offset, "%lc", codepoint);
int printed = snprintf(output + offset, output_len - offset, "%lc", codepoint);
if (printed > 0) {
offset += printed;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/stata/readstat_dta_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ static readstat_error_t dta_emit_fmtlist(readstat_writer_t *writer, dta_ctx_t *c
}
char format[64];
if (format_letter == 'g') {
sprintf(format, "%%%s%d.0g", r_variable->alignment == READSTAT_ALIGNMENT_LEFT ? "-" : "",
snprintf(format, sizeof(format), "%%%s%d.0g", r_variable->alignment == READSTAT_ALIGNMENT_LEFT ? "-" : "",
display_width);
} else {
sprintf(format, "%%%s%ds",
snprintf(format, sizeof(format), "%%%s%ds",
r_variable->alignment == READSTAT_ALIGNMENT_LEFT ? "-" : "",
display_width);
}
Expand Down

0 comments on commit 75dce86

Please sign in to comment.