summaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-14 20:17:57 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-14 20:17:57 -0700
commit3957f6f831909f44164012c623b0870911345129 (patch)
treec3c474f780b59a520e06c0fcc5dc1a03b83b6d41 /asm
parentb292748d9f5fc2ac89a75df4b160a1451a767851 (diff)
downloadnasm-3957f6f831909f44164012c623b0870911345129.tar.gz
%line: quote filenames with double spaces, use unsigned char check
Filenames with double spaces need to be quoted; the preprocessor will otherwise collapse spaces into one. When comparing for control characters and spaces, use an unsigned compare. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r--asm/nasm.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/asm/nasm.c b/asm/nasm.c
index a9793a20..333ba70c 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -446,13 +446,15 @@ static int64_t make_posix_time(const struct tm *tm)
* It is considered necessary if any one of these is true:
* 1. The filename contains control characters;
* 2. The filename starts or ends with a space or quote mark;
- * 3. The filename is empty.
+ * 3. The filename contains more than one space in a row;
+ * 4. The filename is empty.
*
* The filename is returned in a newly allocated buffer.
*/
static char *nasm_quote_filename(const char *fn)
{
- const char *p = fn;
+ const unsigned char *p =
+ (const unsigned char *)fn;
if (!p || !*p)
return nasm_strdup("\"\"");
@@ -460,9 +462,12 @@ static char *nasm_quote_filename(const char *fn)
if (*p <= ' ' || nasm_isquote(*p)) {
goto quote;
} else {
+ unsigned char cutoff = ' ';
+
while (*p) {
- if (*p < ' ')
+ if (*p < cutoff)
goto quote;
+ cutoff = ' ' + (*p == ' ');
p++;
}
if (p[-1] <= ' ' || nasm_isquote(p[-1]))