summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2018-03-25 11:19:59 -0400
committerGitHub <noreply@github.com>2018-03-25 11:19:59 -0400
commit0c446367ce79dfe2a26f4bd7668036477811a279 (patch)
tree8aabd24517bb398682aa8285fa214d1c218c4f48
parent12070ca50067d3abe36a730190f88ee43f2cace9 (diff)
parent8efa0dcfb0e156dee5ca2542f80e9b795a80e3a5 (diff)
Merge pull request #500 from yenatch/fix-scan-includes
Fix scan_includes matching the word "include" in strings.
-rw-r--r--tools/scan_includes.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/tools/scan_includes.c b/tools/scan_includes.c
index 2babdcfb5..63af3bcfb 100644
--- a/tools/scan_includes.c
+++ b/tools/scan_includes.c
@@ -48,9 +48,20 @@ void scan_file(char* filename) {
buffer = strchr(buffer, '\n');
if (!buffer) {
fprintf(stderr, "%s: no newline at end of file\n", filename);
+ break;
}
break;
+ case '"':
+ buffer++;
+ buffer = strchr(buffer, '"');
+ if (!buffer) {
+ fprintf(stderr, "%s: unterminated string\n", filename);
+ break;
+ }
+ buffer++;
+ break;
+
case 'i':
case 'I':
if ((strncmp(buffer, "INCBIN", 6) == 0) || (strncmp(buffer, "incbin", 6) == 0)) {
@@ -60,9 +71,10 @@ void scan_file(char* filename) {
}
if (is_incbin || is_include) {
buffer = strchr(buffer, '"');
- if (!buffer++) {
+ if (!buffer) {
break;
}
+ buffer++;
int length = strcspn(buffer, "\"");
char *include = malloc(length + 1);
strncpy(include, buffer, length);