diff options
author | Piotr Pawel Stefaniak <pstef@FreeBSD.org> | 2018-06-03 17:11:01 +0000 |
---|---|---|
committer | Piotr Pawel Stefaniak <pstef@FreeBSD.org> | 2018-06-03 17:11:01 +0000 |
commit | 7c5f6031feb3df340c45ba8458bf8f6689e89813 (patch) | |
tree | a66b19b7a431c4e25c8191510fc0206883d3b723 /usr.bin/indent | |
parent | bef613ff2ff8c618082b4540c42f975bdeaf64a4 (diff) | |
download | src-7c5f6031feb3df340c45ba8458bf8f6689e89813.tar.gz src-7c5f6031feb3df340c45ba8458bf8f6689e89813.zip |
indent(1): avoid resetting last_bl to a bogus value when reallocating
underlying buffer
Notes
Notes:
svn path=/head/; revision=334571
Diffstat (limited to 'usr.bin/indent')
-rw-r--r-- | usr.bin/indent/indent_globs.h | 9 |
1 files changed, 7 insertions, 2 deletions
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; \ } |