Module Name:    src
Committed By:   fox
Date:           Sun Feb  9 08:10:26 UTC 2020

Modified Files:
        src/usr.bin/xlint/xlint: xlint.c

Log Message:
usr.bin/xlint: Fix -Werror=format-overflow= error.

Replace sprintf(3) with snprintf(3).

Error was reported when build.sh was run with MKLIBCSANITIZER=yes flag.

Reviewed by: kamil@


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/xlint/xlint.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/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.47 src/usr.bin/xlint/xlint/xlint.c:1.48
--- src/usr.bin/xlint/xlint/xlint.c:1.47	Sat Apr 13 15:08:49 2019
+++ src/usr.bin/xlint/xlint/xlint.c	Sun Feb  9 08:10:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.47 2019/04/13 15:08:49 christos Exp $ */
+/* $NetBSD: xlint.c,v 1.48 2020/02/09 08:10:25 fox Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.47 2019/04/13 15:08:49 christos Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.48 2020/02/09 08:10:25 fox Exp $");
 #endif
 
 #include <sys/param.h>
@@ -613,7 +613,7 @@ fname(const char *name)
 	const	char *bn, *suff;
 	char	**args, *ofn, *pathname;
 	const char *CC;
-	size_t	len;
+	size_t	buff_size, len;
 	int is_stdin;
 	int	fd;
 
@@ -648,10 +648,10 @@ fname(const char *name)
 			warnx("-i not supported without -o for standard input");
 			return;
 		}
-		ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2));
+		buff_size = strlen(bn) + (bn == suff ? 4 : 2);
+		ofn = xmalloc(buff_size);
 		len = bn == suff ? strlen(bn) : (size_t)((suff - 1) - bn);
-		(void)sprintf(ofn, "%.*s", (int)len, bn);
-		(void)strcat(ofn, ".ln");
+		(void)snprintf(ofn, buff_size, "%.*s.ln", (int)len, bn);
 	} else {
 		ofn = xmalloc(strlen(tmpdir) + sizeof ("lint1.XXXXXX"));
 		(void)sprintf(ofn, "%slint1.XXXXXX", tmpdir);

Reply via email to