Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jun 2018 17:11:01 +0000 (UTC)
From:      Piotr Pawel Stefaniak <pstef@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334571 - head/usr.bin/indent
Message-ID:  <201806031711.w53HB1vN005541@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pstef
Date: Sun Jun  3 17:11:01 2018
New Revision: 334571
URL: https://svnweb.freebsd.org/changeset/base/334571

Log:
  indent(1): avoid resetting last_bl to a bogus value when reallocating
  underlying buffer

Modified:
  head/usr.bin/indent/indent_globs.h

Modified: head/usr.bin/indent/indent_globs.h
==============================================================================
--- head/usr.bin/indent/indent_globs.h	Sun Jun  3 17:07:56 2018	(r334570)
+++ head/usr.bin/indent/indent_globs.h	Sun Jun  3 17:11:01 2018	(r334571)
@@ -67,12 +67,17 @@ FILE       *output;		/* the output file */
 	if (e_com >= l_com) { \
 	    int nsize = l_com-s_com+400; \
 	    int com_len = e_com - s_com; \
-	    int blank_pos = last_bl - s_com; \
+	    int blank_pos; \
+	    if (last_bl != NULL) \
+		blank_pos = last_bl - combuf; \
+	    else \
+		blank_pos = -1; \
 	    combuf = (char *) realloc(combuf, nsize); \
 	    if (combuf == NULL) \
 		err(1, NULL); \
 	    e_com = combuf + com_len + 1; \
-	    last_bl = combuf + blank_pos + 1; \
+	    if (blank_pos > 0) \
+		last_bl = combuf + blank_pos; \
 	    l_com = combuf + nsize - 5; \
 	    s_com = combuf + 1; \
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806031711.w53HB1vN005541>