Skip to content

Commit 2afb925

Browse files
committed
Replace sprintf() to snprintf() #212
1 parent 0ccc6a7 commit 2afb925

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

library/lattice/test/src/usage_tetengo.lattice.viterbi_c.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,18 @@ const char* to_string(const tetengo_lattice_path_t* const p_path)
277277
{
278278
if (i > 0)
279279
{
280-
strcat(result, "-");
280+
strncat(result, "-", sizeof(result) - strlen(result) - 1);
281281
}
282-
strcat(result, "[");
283-
strcat(result, value_of(&p_nodes[i], i == 0));
284-
strcat(result, "]");
282+
strncat(result, "[", sizeof(result) - strlen(result) - 1);
283+
strncat(result, value_of(&p_nodes[i], i == 0), sizeof(result) - strlen(result) - 1);
284+
strncat(result, "]", sizeof(result) - strlen(result) - 1);
285285
}
286-
strcat(result, " (");
287-
sprintf(result + strlen(result), "%d", tetengo_lattice_path_cost(p_path));
288-
strcat(result, ")");
286+
strncat(result, " (", sizeof(result) - strlen(result) - 1);
287+
snprintf(result + strlen(result), sizeof(result) - strlen(result), "%d", tetengo_lattice_path_cost(p_path));
288+
strncat(result, ")", sizeof(result) - strlen(result) - 1);
289289
free(p_nodes);
290290
}
291-
strcat(result, "\n");
291+
strncat(result, "\n", sizeof(result) - strlen(result) - 1);
292292
return result;
293293
}
294294
// [viterbi]

sample/json2timetable/src/printStationTimetable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static const char* create_departure(const size_t minute, const char* const desti
2626
{
2727
return NULL;
2828
}
29-
sprintf(p_departure, "%02u%s", (unsigned int)minute, encoded);
29+
snprintf(p_departure, 2 + strlen(encoded) + 1, "%02u%s", (unsigned int)minute, encoded);
3030
free((void*)encoded);
3131
return p_departure;
3232
}

0 commit comments

Comments
 (0)