CVS commit: src/games/fortune/unstr

2020-04-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr 30 12:40:11 UTC 2020

Modified Files:
src/games/fortune/unstr: unstr.c

Log Message:
Simplify, little KNF


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/games/fortune/unstr/unstr.c

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



CVS commit: src/games/fortune/unstr

2020-04-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr 30 12:40:11 UTC 2020

Modified Files:
src/games/fortune/unstr: unstr.c

Log Message:
Simplify, little KNF


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/games/fortune/unstr/unstr.c

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

Modified files:

Index: src/games/fortune/unstr/unstr.c
diff -u src/games/fortune/unstr/unstr.c:1.15 src/games/fortune/unstr/unstr.c:1.16
--- src/games/fortune/unstr/unstr.c:1.15	Wed Apr 29 17:00:42 2020
+++ src/games/fortune/unstr/unstr.c	Thu Apr 30 08:40:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $	*/
+/*	$NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)unstr.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $");
+__RCSID("$NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,19 +59,19 @@ __RCSID("$NetBSD: unstr.c,v 1.15 2020/04
  *	Ken Arnold		Aug 13, 1978
  */
 
-# include	
-# include	
-# include	
-# include	
-# include	
-# include	
-# include	
-# include	
-# include	"strfile.h"
-
-# ifndef MAXPATHLEN
-# define	MAXPATHLEN	1024
-# endif	/* MAXPATHLEN */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "strfile.h"
+
+#ifndef MAXPATHLEN
+#define	MAXPATHLEN	1024
+#endif	/* MAXPATHLEN */
 
 char	*Infile,			/* name of input file */
 	Datafile[MAXPATHLEN],		/* name of data file */
@@ -91,9 +91,9 @@ main(int ac __unused, char **av)
 
 	getargs(av);
 	if ((Inf = fopen(Infile, "r")) == NULL)
-		err(1, "fopen %s", Infile);
+		err(EXIT_FAILURE, "fopen %s", Infile);
 	if ((Dataf = fopen(Datafile, "r")) == NULL)
-		err(1, "fopen %s", Datafile);
+		err(EXIT_FAILURE, "fopen %s", Datafile);
 	(void) fread((char *) , sizeof tbl, 1, Dataf);
 	BE32TOH(tbl.str_version);
 	BE32TOH(tbl.str_numstr);
@@ -108,19 +108,19 @@ main(int ac __unused, char **av)
 	order_unstr();
 	(void) fclose(Inf);
 	(void) fclose(Dataf);
-	exit(0);
+	return EXIT_SUCCESS;
 }
 
 void
 getargs(char *av[])
 {
-	if (!*++av || (strlen(*av) + sizeof(".dat")) > sizeof(Datafile)) {
-		(void) fprintf(stderr, "usage: unstr datafile\n");
-		exit(1);
+	if (!*++av ||
+	(size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) >
+	sizeof(Datafile)) {
+		(void) fprintf(stderr, "Usage: %s datafile\n", getprogname());
+		exit(EXIT_FAILURE);
 	}
 	Infile = *av;
-	(void) strcpy(Datafile, Infile);
-	(void) strcat(Datafile, ".dat");
 }
 
 void



CVS commit: src/games/fortune/unstr

2020-04-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Wed Apr 29 21:00:42 UTC 2020

Modified Files:
src/games/fortune/unstr: unstr.c

Log Message:
unstr: Check that the input filename fits in the buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/games/fortune/unstr/unstr.c

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

Modified files:

Index: src/games/fortune/unstr/unstr.c
diff -u src/games/fortune/unstr/unstr.c:1.14 src/games/fortune/unstr/unstr.c:1.15
--- src/games/fortune/unstr/unstr.c:1.14	Tue Jun 19 05:46:08 2012
+++ src/games/fortune/unstr/unstr.c	Wed Apr 29 21:00:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: unstr.c,v 1.14 2012/06/19 05:46:08 dholland Exp $	*/
+/*	$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)unstr.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: unstr.c,v 1.14 2012/06/19 05:46:08 dholland Exp $");
+__RCSID("$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -114,7 +114,7 @@ main(int ac __unused, char **av)
 void
 getargs(char *av[])
 {
-	if (!*++av) {
+	if (!*++av || (strlen(*av) + sizeof(".dat")) > sizeof(Datafile)) {
 		(void) fprintf(stderr, "usage: unstr datafile\n");
 		exit(1);
 	}



CVS commit: src/games/fortune/unstr

2020-04-29 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Wed Apr 29 21:00:42 UTC 2020

Modified Files:
src/games/fortune/unstr: unstr.c

Log Message:
unstr: Check that the input filename fits in the buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/games/fortune/unstr/unstr.c

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