aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-09-15 09:56:36 +0100
committerRon Yorston <rmy@pobox.com>2024-09-15 09:56:36 +0100
commit9376eebd8d16ce38278ee709177e9e7fd5d7ec14 (patch)
tree6078357e71b675b7883b9239f4a65f5e60d00038
parentb21546ddbea20447054e60c893b64849f54be7d9 (diff)
downloadbusybox-w32-9376eebd8d16ce38278ee709177e9e7fd5d7ec14.tar.gz
busybox-w32-9376eebd8d16ce38278ee709177e9e7fd5d7ec14.tar.bz2
busybox-w32-9376eebd8d16ce38278ee709177e9e7fd5d7ec14.zip
make: fix error reporting for included filesFRP-5467-g9376eebd8
The global variables 'makefile' and 'lineno' weren't properly reset after a recursive call to input(). As a result error messages for included files could refer to the wrong file or line number. Restore 'makefile' and 'lineno' immediately after a rescursive call to input(). This also requires a different fix for commit b21546ddb (make: fix test for include with no pathnames). Adds 16 bytes in the 32-bit build.
-rw-r--r--miscutils/make.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/miscutils/make.c b/miscutils/make.c
index bd3b23f21..8d953f9fc 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -2073,23 +2073,27 @@ input(FILE *fd, int ilevel)
2073 if (ilevel > 16) 2073 if (ilevel > 16)
2074 error("too many includes"); 2074 error("too many includes");
2075 2075
2076 count = 0;
2076 q = expanded = expand_macros(p + 7, FALSE); 2077 q = expanded = expand_macros(p + 7, FALSE);
2077 while ((p = gettok(&q)) != NULL) { 2078 while ((p = gettok(&q)) != NULL) {
2078 FILE *ifd; 2079 FILE *ifd;
2079 2080
2081 ++count;
2080 if (!POSIX_2017) { 2082 if (!POSIX_2017) {
2081 // Try to create include file or bring it up-to-date 2083 // Try to create include file or bring it up-to-date
2082 opts |= OPT_include; 2084 opts |= OPT_include;
2083 make(newname(p), 1); 2085 make(newname(p), 1);
2084 opts &= ~OPT_include; 2086 opts &= ~OPT_include;
2085 } 2087 }
2086 makefile = p;
2087 if ((ifd = fopen(p, "r")) == NULL) { 2088 if ((ifd = fopen(p, "r")) == NULL) {
2088 if (!minus) 2089 if (!minus)
2089 error("can't open include file '%s'", p); 2090 error("can't open include file '%s'", p);
2090 } else { 2091 } else {
2092 makefile = p;
2091 input(ifd, ilevel + 1); 2093 input(ifd, ilevel + 1);
2092 fclose(ifd); 2094 fclose(ifd);
2095 makefile = old_makefile;
2096 lineno = old_lineno;
2093 } 2097 }
2094 if (POSIX_2017) 2098 if (POSIX_2017)
2095 break; 2099 break;
@@ -2100,14 +2104,11 @@ input(FILE *fd, int ilevel)
2100 if (p == NULL || gettok(&q)) { 2104 if (p == NULL || gettok(&q)) {
2101 error("one include file per line"); 2105 error("one include file per line");
2102 } 2106 }
2103 } else if (makefile == old_makefile) { 2107 } else if (count == 0) {
2104 // In POSIX 2024 no include file is unspecified behaviour. 2108 // In POSIX 2024 no include file is unspecified behaviour.
2105 if (posix) 2109 if (posix)
2106 error("no include file"); 2110 error("no include file");
2107 } 2111 }
2108
2109 makefile = old_makefile;
2110 lineno = old_lineno;
2111 goto end_loop; 2112 goto end_loop;
2112 } 2113 }
2113 2114