Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: prevent division by zero



details:   https://anonhg.NetBSD.org/src/rev/a0dba3f8811e
branches:  trunk
changeset: 1024011:a0dba3f8811e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 07 18:19:07 2021 +0000

description:
indent: prevent division by zero

diffstat:

 usr.bin/indent/indent.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r 4c9db758b01a -r a0dba3f8811e usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Oct 07 18:07:25 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Oct 07 18:19:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.108 2021/10/05 18:50:42 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.108 2021/10/05 18:50:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -491,6 +491,10 @@
            : opt.comment_column;
     if (opt.continuation_indent == 0)
        opt.continuation_indent = opt.indent_size;
+    if (!(1 <= opt.tabsize && opt.tabsize <= 80))
+       errx(EXIT_FAILURE, "invalid tabsize %d", opt.tabsize);
+    if (!(1 <= opt.indent_size && opt.indent_size <= 80))
+       errx(EXIT_FAILURE, "invalid indentation %d", opt.indent_size);
 }
 
 static void



Home | Main Index | Thread Index | Old Index