diff options
author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2016-08-01 19:24:01 +0000 |
---|---|---|
committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2016-08-01 19:24:01 +0000 |
commit | 707e8dae2d256970505f34e3e38d5505ff780e72 (patch) | |
tree | 5546fbf82f3cc2e69e4e79e5c86dd16db2c2a46b /usr.bin/indent | |
parent | 87ff568c2687059f890a8065cdfef66030ed37fb (diff) | |
download | src-707e8dae2d256970505f34e3e38d5505ff780e72.tar.gz src-707e8dae2d256970505f34e3e38d5505ff780e72.zip |
indent: Avoid using values of pointers that refer to deallocated space.
For now maintain the local style in this file.
Reviewed by: jilles
Reference:
https://github.com/pstef/freebsd_indent/commit/9099a9f17bc5f579514a4c11111f5cf3df6624c6
Differential Revision: https://reviews.freebsd.org/D6966 (Partial)
Submitted by: Piotr Stefaniak
Notes
Notes:
svn path=/head/; revision=303629
Diffstat (limited to 'usr.bin/indent')
-rw-r--r-- | usr.bin/indent/indent_globs.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index 78873c0e9004..3f8e17cb9186 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -57,41 +57,46 @@ FILE *output; /* the output file */ #define CHECK_SIZE_CODE \ if (e_code >= l_code) { \ int nsize = l_code-s_code+400; \ + int code_len = e_code-s_code; \ codebuf = (char *) realloc(codebuf, nsize); \ if (codebuf == NULL) \ err(1, NULL); \ - e_code = codebuf + (e_code-s_code) + 1; \ + e_code = codebuf + code_len + 1; \ l_code = codebuf + nsize - 5; \ s_code = codebuf + 1; \ } #define CHECK_SIZE_COM \ 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; \ combuf = (char *) realloc(combuf, nsize); \ if (combuf == NULL) \ err(1, NULL); \ - e_com = combuf + (e_com-s_com) + 1; \ - last_bl = combuf + (last_bl-s_com) + 1; \ + e_com = combuf + com_len + 1; \ + last_bl = combuf + blank_pos + 1; \ l_com = combuf + nsize - 5; \ s_com = combuf + 1; \ } #define CHECK_SIZE_LAB \ if (e_lab >= l_lab) { \ int nsize = l_lab-s_lab+400; \ + int label_len = e_lab - s_lab; \ labbuf = (char *) realloc(labbuf, nsize); \ if (labbuf == NULL) \ err(1, NULL); \ - e_lab = labbuf + (e_lab-s_lab) + 1; \ + e_lab = labbuf + label_len + 1; \ l_lab = labbuf + nsize - 5; \ s_lab = labbuf + 1; \ } #define CHECK_SIZE_TOKEN \ if (e_token >= l_token) { \ int nsize = l_token-s_token+400; \ + int token_len = e_token - s_token; \ tokenbuf = (char *) realloc(tokenbuf, nsize); \ if (tokenbuf == NULL) \ err(1, NULL); \ - e_token = tokenbuf + (e_token-s_token) + 1; \ + e_token = tokenbuf + token_len + 1; \ l_token = tokenbuf + nsize - 5; \ s_token = tokenbuf + 1; \ } |