From a9d9335b20a0b708fae1b978f70348aec998356a Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 1 Apr 2014 21:49:16 -0400 Subject: textscreen: Use safe string functions. Define TXT_{StringCopy,StringConcat,snprintf,vsnprintf} as analogs of the m_misc.c versions so that the textscreen library does not need a dependency on the Doom code, and change all textscreen code to use these instead of unsafe functions. This fixes #372. --- textscreen/examples/calculator.c | 6 +++--- textscreen/examples/guitest.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'textscreen/examples') diff --git a/textscreen/examples/calculator.c b/textscreen/examples/calculator.c index 7c77e838..3db60ef7 100644 --- a/textscreen/examples/calculator.c +++ b/textscreen/examples/calculator.c @@ -49,7 +49,7 @@ void UpdateInputBox(void) { char buf[20]; - sprintf(buf, " %i", input_value); + TXT_snprintf(buf, sizeof(buf), " %i", input_value); TXT_SetLabel(input_box, buf); } @@ -76,7 +76,7 @@ void AddNumberButton(txt_table_t *table, int value) val_copy = malloc(sizeof(int)); *val_copy = value; - sprintf(buf, " %i ", value); + TXT_snprintf(buf, sizeof(buf), " %i ", value); TXT_AddWidget(table, TXT_NewButton2(buf, InsertNumber, val_copy)); } @@ -98,7 +98,7 @@ void AddOperatorButton(txt_table_t *table, char *label, operator_t op) op_copy = malloc(sizeof(operator_t)); *op_copy = op; - sprintf(buf, " %s ", label); + TXT_snprintf(buf, sizeof(buf), " %s ", label); TXT_AddWidget(table, TXT_NewButton2(buf, Operator, op_copy)); } diff --git a/textscreen/examples/guitest.c b/textscreen/examples/guitest.c index 08faae98..3904ffa9 100644 --- a/textscreen/examples/guitest.c +++ b/textscreen/examples/guitest.c @@ -76,13 +76,13 @@ void UpdateLabel(TXT_UNCAST_ARG(widget), void *user_data) { char buf[40]; - strcpy(buf, " Current value: "); + TXT_StringCopy(buf, " Current value: ", sizeof(buf)); if (cheesy) { - strcat(buf, "Cheesy "); + TXT_StringConcat(buf, "Cheesy ", sizeof(buf)); } - strcat(buf, radio_values[radiobutton_value]); - strcat(buf, "\n"); + TXT_StringConcat(buf, radio_values[radiobutton_value], sizeof(buf)); + TXT_StringConcat(buf, "\n", sizeof(buf)); TXT_SetLabel(value_label, buf); } @@ -119,11 +119,11 @@ void SetupWindow(void) for (i=0; i<5; ++i) { - sprintf(buf, "Option %i in a table:", i + 1); + TXT_snprintf(buf, sizeof(buf), "Option %i in a table:", i + 1); TXT_AddWidget(table, TXT_NewLabel(buf)); - sprintf(buf, " Button %i-1 ", i + 1); + TXT_snprintf(buf, sizeof(buf), " Button %i-1 ", i + 1); TXT_AddWidget(table, TXT_NewButton(buf)); - sprintf(buf, " Button %i-2 ", i + 1); + TXT_snprintf(buf, sizeof(buf), " Button %i-2 ", i + 1); TXT_AddWidget(table, TXT_NewButton(buf)); } -- cgit v1.2.3