From 7c5f6031feb3df340c45ba8458bf8f6689e89813 Mon Sep 17 00:00:00 2001 From: Piotr Pawel Stefaniak Date: Sun, 3 Jun 2018 17:11:01 +0000 Subject: indent(1): avoid resetting last_bl to a bogus value when reallocating underlying buffer --- usr.bin/indent/indent_globs.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'usr.bin/indent') diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index c5cc17199993..8e8568117f85 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -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; \ } -- cgit v1.2.3