Module Name:    src
Committed By:   sjg
Date:           Wed Jan  3 20:24:16 UTC 2024

Modified Files:
        src/usr.bin/make: parse.c

Log Message:
make: do not add newline to an empty buffer

When LoadFile reads from /dev/null the buffer will be empty,
appending "\n" just results in an unnecessary extra call
to ParseRawLine.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.713 -r1.714 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.713 src/usr.bin/make/parse.c:1.714
--- src/usr.bin/make/parse.c:1.713	Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/parse.c	Wed Jan  3 20:24:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.713 2023/12/29 20:43:58 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.713 2023/12/29 20:43:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -383,7 +383,7 @@ LoadFile(const char *path, int fd)
 	}
 	assert(buf.len <= buf.cap);
 
-	if (!Buf_EndsWith(&buf, '\n'))
+	if (buf.len > 0 && !Buf_EndsWith(&buf, '\n'))
 		Buf_AddByte(&buf, '\n');
 
 	return buf;		/* may not be null-terminated */

Reply via email to