Module Name:    src
Committed By:   rillig
Date:           Thu Mar 11 22:32:06 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c lexi.c pr_comment.c

Log Message:
indent: reduce indentation of check_size functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/pr_comment.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/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.42 src/usr.bin/indent/indent.c:1.43
--- src/usr.bin/indent/indent.c:1.42	Thu Mar 11 22:28:30 2021
+++ src/usr.bin/indent/indent.c	Thu Mar 11 22:32:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.42 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.43 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -136,31 +136,33 @@ char        bakfile[MAXPATHLEN] = "";
 static void
 check_size_code(size_t desired_size)
 {
-    if (e_code + (desired_size) >= l_code) {
-	int nsize = l_code - s_code + 400 + desired_size;
-	int code_len = e_code - s_code;
-	codebuf = realloc(codebuf, nsize);
-	if (codebuf == NULL)
-	    err(1, NULL);
-	e_code = codebuf + code_len + 1;
-	l_code = codebuf + nsize - 5;
-	s_code = codebuf + 1;
-    }
+    if (e_code + (desired_size) < l_code)
+        return;
+
+    size_t nsize = l_code - s_code + 400 + desired_size;
+    size_t code_len = e_code - s_code;
+    codebuf = realloc(codebuf, nsize);
+    if (codebuf == NULL)
+	err(1, NULL);
+    e_code = codebuf + code_len + 1;
+    l_code = codebuf + nsize - 5;
+    s_code = codebuf + 1;
 }
 
 static void
 check_size_label(size_t desired_size)
 {
-    if (e_lab + (desired_size) >= l_lab) {
-	int nsize = l_lab - s_lab + 400 + desired_size;
-	int label_len = e_lab - s_lab;
-	labbuf = realloc(labbuf, nsize);
-	if (labbuf == NULL)
-	    err(1, NULL);
-	e_lab = labbuf + label_len + 1;
-	l_lab = labbuf + nsize - 5;
-	s_lab = labbuf + 1;
-    }
+    if (e_lab + (desired_size) < l_lab)
+        return;
+
+    size_t nsize = l_lab - s_lab + 400 + desired_size;
+    size_t label_len = e_lab - s_lab;
+    labbuf = realloc(labbuf, nsize);
+    if (labbuf == NULL)
+	err(1, NULL);
+    e_lab = labbuf + label_len + 1;
+    l_lab = labbuf + nsize - 5;
+    s_lab = labbuf + 1;
 }
 
 #if HAVE_CAPSICUM

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.34 src/usr.bin/indent/lexi.c:1.35
--- src/usr.bin/indent/lexi.c:1.34	Thu Mar 11 22:28:30 2021
+++ src/usr.bin/indent/lexi.c	Thu Mar 11 22:32:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.34 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.35 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -196,16 +196,17 @@ inbuf_next(void)
 static void
 check_size_token(size_t desired_size)
 {
-    if (e_token + (desired_size) >= l_token) {
-	int nsize = l_token - s_token + 400 + desired_size;
-	int token_len = e_token - s_token;
-	tokenbuf = realloc(tokenbuf, nsize);
-	if (tokenbuf == NULL)
-	    err(1, NULL);
-	e_token = tokenbuf + token_len + 1;
-	l_token = tokenbuf + nsize - 5;
-	s_token = tokenbuf + 1;
-    }
+    if (e_token + (desired_size) < l_token)
+        return;
+
+    size_t nsize = l_token - s_token + 400 + desired_size;
+    size_t token_len = e_token - s_token;
+    tokenbuf = realloc(tokenbuf, nsize);
+    if (tokenbuf == NULL)
+	err(1, NULL);
+    e_token = tokenbuf + token_len + 1;
+    l_token = tokenbuf + nsize - 5;
+    s_token = tokenbuf + 1;
 }
 
 static int
@@ -690,8 +691,7 @@ void
 alloc_typenames(void)
 {
 
-    typenames = malloc(sizeof(typenames[0]) *
-        (typename_count = 16));
+    typenames = malloc(sizeof(typenames[0]) * (typename_count = 16));
     if (typenames == NULL)
 	err(1, NULL);
 }

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.17 src/usr.bin/indent/pr_comment.c:1.18
--- src/usr.bin/indent/pr_comment.c:1.17	Thu Mar 11 22:28:30 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Mar 11 22:32:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.17 2021/03/11 22:28:30 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.17 2021/03/11 22:28:30 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -62,23 +62,20 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 static void
 check_size_comment(size_t desired_size, char **last_bl_ptr)
 {
-    if (e_com + (desired_size) >= l_com) {
-	int nsize = l_com - s_com + 400 + desired_size;
-	int com_len = e_com - s_com;
-	int blank_pos;
-	if (*last_bl_ptr != NULL)
-	    blank_pos = *last_bl_ptr - combuf;
-	else
-	    blank_pos = -1;
-	combuf = realloc(combuf, nsize);
-	if (combuf == NULL)
-	    err(1, NULL);
-	e_com = combuf + com_len + 1;
-	if (blank_pos > 0)
-	    *last_bl_ptr = combuf + blank_pos;
-	l_com = combuf + nsize - 5;
-	s_com = combuf + 1;
-    }
+    if (e_com + (desired_size) < l_com)
+        return;
+
+    size_t nsize = l_com - s_com + 400 + desired_size;
+    size_t com_len = e_com - s_com;
+    ssize_t blank_pos = *last_bl_ptr != NULL ? *last_bl_ptr - combuf : -1;
+    combuf = realloc(combuf, nsize);
+    if (combuf == NULL)
+	err(1, NULL);
+    e_com = combuf + com_len + 1;
+    if (blank_pos > 0)
+	*last_bl_ptr = combuf + blank_pos;
+    l_com = combuf + nsize - 5;
+    s_com = combuf + 1;
 }
 
 /*

Reply via email to