Skip to content

Commit

Permalink
chore: remove usage of sprintf (carp-lang#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve authored Jan 31, 2023
1 parent 7ab466e commit ca5774b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/carp_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ Array Pattern_match_MINUS_all_MINUS_groups(Pattern *p, String *s) {
String Pattern_internal_add_char(String a, Char b) {
if (!a) {
String buffer = CARP_MALLOC(2);
sprintf(buffer, "%c", b);
snprintf(buffer, 1, "%c", b);
return buffer;
}

int len = strlen(a) + 2;
String buffer = CARP_MALLOC(len);
sprintf(buffer, "%s%c", a, b);
snprintf(buffer, len-1, "%s%c", a, b);
CARP_FREE(a);
return buffer;
}
Expand Down Expand Up @@ -645,7 +645,7 @@ String Pattern_substitute(Pattern *p, String *s, String *t, int ns) {

int l = strlen(res) + strlen(str) + 1;
String buffer = CARP_MALLOC(l);
sprintf(buffer, "%s%s", res, str);
snprintf(buffer, l-1, "%s%s", res, str);
CARP_FREE(res);
return buffer;
}
Expand All @@ -671,7 +671,7 @@ String Pattern_str(Pattern *p) {
String Pattern_prn(Pattern *p) {
int n = strlen(*p) + 4;
String buffer = CARP_MALLOC(n);
sprintf(buffer, "#\"%s\"", *p);
snprintf(buffer, n-1, "#\"%s\"", *p);
return buffer;
}

Expand Down

0 comments on commit ca5774b

Please sign in to comment.