Sat Oct 5 20:22:36 2019 UTC ()
add an abort for a case that can't happen


(christos)
diff -r1.34 -r1.35 src/usr.bin/sed/main.c

cvs diff -r1.34 -r1.35 src/usr.bin/sed/main.c (expand / switch to unified diff)

--- src/usr.bin/sed/main.c 2015/03/12 12:40:41 1.34
+++ src/usr.bin/sed/main.c 2019/10/05 20:22:36 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.34 2015/03/12 12:40:41 christos Exp $ */ 1/* $NetBSD: main.c,v 1.35 2019/10/05 20:22:36 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson. 4 * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson.
5 * Copyright (c) 1992 Diomidis Spinellis. 5 * Copyright (c) 1992 Diomidis Spinellis.
6 * Copyright (c) 1992, 1993 6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved. 7 * The Regents of the University of California. All rights reserved.
8 * 8 *
9 * This code is derived from software contributed to Berkeley by 9 * This code is derived from software contributed to Berkeley by
10 * Diomidis Spinellis of Imperial College, University of London. 10 * Diomidis Spinellis of Imperial College, University of London.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 */ 35 */
36 36
37#if HAVE_NBTOOL_CONFIG_H 37#if HAVE_NBTOOL_CONFIG_H
38#include "nbtool_config.h" 38#include "nbtool_config.h"
39#endif 39#endif
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__RCSID("$NetBSD: main.c,v 1.34 2015/03/12 12:40:41 christos Exp $"); 42__RCSID("$NetBSD: main.c,v 1.35 2019/10/05 20:22:36 christos Exp $");
43#ifdef __FBSDID 43#ifdef __FBSDID
44__FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $"); 44__FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $");
45#endif 45#endif
46 46
47#ifndef lint 47#ifndef lint
48__COPYRIGHT("@(#) Copyright (c) 1992, 1993\ 48__COPYRIGHT("@(#) Copyright (c) 1992, 1993\
49 The Regents of the University of California. All rights reserved."); 49 The Regents of the University of California. All rights reserved.");
50#endif 50#endif
51 51
52#if 0 52#if 0
53static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94"; 53static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94";
54#endif 54#endif
55 55
@@ -258,26 +258,28 @@ again: @@ -258,26 +258,28 @@ again:
258 fname = script->s; 258 fname = script->s;
259 state = ST_FILE; 259 state = ST_FILE;
260 goto again; 260 goto again;
261 case CU_STRING: 261 case CU_STRING:
262 if (((size_t)snprintf(string_ident, 262 if (((size_t)snprintf(string_ident,
263 sizeof(string_ident), "\"%s\"", script->s)) >= 263 sizeof(string_ident), "\"%s\"", script->s)) >=
264 sizeof(string_ident) - 1) 264 sizeof(string_ident) - 1)
265 (void)strcpy(string_ident + 265 (void)strcpy(string_ident +
266 sizeof(string_ident) - 6, " ...\""); 266 sizeof(string_ident) - 6, " ...\"");
267 fname = string_ident; 267 fname = string_ident;
268 s = script->s; 268 s = script->s;
269 state = ST_STRING; 269 state = ST_STRING;
270 goto again; 270 goto again;
 271 default:
 272 abort();
271 } 273 }
272 case ST_FILE: 274 case ST_FILE:
273 if ((p = fgets(buf, n, f)) != NULL) { 275 if ((p = fgets(buf, n, f)) != NULL) {
274 linenum++; 276 linenum++;
275 if (linenum == 1 && buf[0] == '#' && buf[1] == 'n') 277 if (linenum == 1 && buf[0] == '#' && buf[1] == 'n')
276 nflag = 1; 278 nflag = 1;
277 if (more != NULL) 279 if (more != NULL)
278 *more = !feof(f); 280 *more = !feof(f);
279 return (p); 281 return (p);
280 } 282 }
281 script = script->next; 283 script = script->next;
282 (void)fclose(f); 284 (void)fclose(f);
283 state = ST_EOF; 285 state = ST_EOF;