Skip to content

Commit 038e488

Browse files
author
J. Scott Berg
committed
Fix strcat on overlapping strings
1 parent 1c74a6c commit 038e488

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/mad_table.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "madx.h"
2-
2+
#include <stdio.h>
33
#ifndef _WIN32
44
#include <sys/utsname.h> // for uname
55
#endif
@@ -702,6 +702,8 @@ table_value(void)
702702
double val = zero;
703703
int ntok, col, row;
704704
char** toks;
705+
char *tmp_row_name;
706+
unsigned l_tmp_row_name;
705707
struct table* table;
706708
char temp[NAME_L];
707709

@@ -720,17 +722,16 @@ table_value(void)
720722
{
721723
if (ntok > 2)
722724
{ /* find row - else current (dynamic), or 0 */
723-
/* start mod - HG 26.3.2011 */
724-
if (ntok > 5)
725+
if (ntok > 5 && *toks[2] == '[' && *toks[4] == ']')
725726
{ /* check for [ count ] and convert to ->count */
726-
if (*toks[2] == '[' && *toks[4] == ']')
727-
{
728-
strcat(toks[1], "->");
729-
strcat(toks[1], toks[3]);
730-
}
727+
l_tmp_row_name = strlen(toks[1])+strlen(toks[3])+3;
728+
tmp_row_name = malloc(l_tmp_row_name);
729+
snprintf(tmp_row_name,l_tmp_row_name,"%s->%s",toks[1],toks[3]);
730+
row = table_row(table, tmp_row_name);
731+
free(tmp_row_name);
731732
}
732-
/* end mod - HG 26.3.2011 */
733-
row = table_row(table, toks[1]);
733+
else
734+
row = table_row(table, toks[1]);
734735
}
735736
else
736737
{

0 commit comments

Comments
 (0)