Fix out of bounds memory problems in handling simple macro arguments

Fixes handling macro in swigmacros.swg:
  #define %arg(Arg...)        Arg

AddressSanitizer error running Python test-suite.
This commit is contained in:
William S Fulton 2018-01-13 07:33:28 +00:00
commit ab5559f51c

View file

@ -930,9 +930,10 @@ static String *expand_macro(String *name, List *args, String *line_file) {
namelen = Len(aname); namelen = Len(aname);
a = strstr(s, name); a = strstr(s, name);
while (a) { while (a) {
char ca = a[namelen + 1]; char ca = a[namelen];
if (!isidchar((int) ca)) { if (!isidchar((int) ca)) {
/* Matched the entire vararg name, not just a prefix */ /* Matched the entire vararg name, not just a prefix */
if (a > s) {
t = a - 1; t = a - 1;
if (*t == '\002') { if (*t == '\002') {
t--; t--;
@ -946,6 +947,7 @@ static String *expand_macro(String *name, List *args, String *line_file) {
} }
} }
} }
}
a = strstr(a + namelen, name); a = strstr(a + namelen, name);
} }
} }