diff options
| author | frosty <frostinator33@airmail.cc> | 2026-10-27 20:31:28 -0400 |
|---|---|---|
| committer | frosty <frostinator33@airmail.cc> | 2026-10-27 20:33:50 -0400 |
| commit | 250898c638f07ace6bc7167faede93113c8fd0db (patch) | |
| tree | 310addbedcaaf76da98df22434a4f4711c8ba963 /src/Infobox/UnitConversion.c | |
| parent | bd3da2232540ea4c78e7ac35e2c90c38c8a3c410 (diff) | |
refactor: replace potentially unsafe string functions with snprintf
Diffstat (limited to 'src/Infobox/UnitConversion.c')
| -rw-r--r-- | src/Infobox/UnitConversion.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Infobox/UnitConversion.c b/src/Infobox/UnitConversion.c index 4269f3c..cf068fd 100644 --- a/src/Infobox/UnitConversion.c +++ b/src/Infobox/UnitConversion.c @@ -360,7 +360,7 @@ static int parse_conversion_query(const char *query, double *value, while (try_len > 0) { *to_unit = find_unit(try_buf); if (*to_unit) { - strcpy(to_part, try_buf); + snprintf(to_part, sizeof(to_part), "%s", try_buf); break; } char *last_space = strrchr(try_buf, ' '); @@ -443,34 +443,34 @@ static const char *pluralize(const char *unit, double value, char *buf, if (len == 0 || bufsize == 0) return unit; - strncpy(buf, unit, bufsize - 1); - buf[bufsize - 1] = '\0'; + snprintf(buf, bufsize, "%s", unit); if (strcmp(unit, "foot") == 0 || strcmp(unit, "square foot") == 0) { if (is_one) - strcpy(buf, unit); + snprintf(buf, bufsize, "%s", unit); else - strcpy(buf, strcmp(unit, "square foot") == 0 ? "square feet" : "feet"); + snprintf(buf, bufsize, "%s", + strcmp(unit, "square foot") == 0 ? "square feet" : "feet"); return buf; } if (strcmp(unit, "inch") == 0 || strcmp(unit, "square inch") == 0) { if (is_one) - strcpy(buf, unit); + snprintf(buf, bufsize, "%s", unit); else - strcpy(buf, - strcmp(unit, "square inch") == 0 ? "square inches" : "inches"); + snprintf(buf, bufsize, "%s", + strcmp(unit, "square inch") == 0 ? "square inches" : "inches"); return buf; } if (strcmp(unit, "stone") == 0) { if (is_one) - strcpy(buf, "stone"); + snprintf(buf, bufsize, "%s", "stone"); else - strcpy(buf, "stones"); + snprintf(buf, bufsize, "%s", "stones"); return buf; } if (strcmp(unit, "celsius") == 0 || strcmp(unit, "fahrenheit") == 0 || strcmp(unit, "kelvin") == 0) { - strcpy(buf, unit); + snprintf(buf, bufsize, "%s", unit); return buf; } |
