Introduction
Introduction Statistics Contact Development Disclaimer Help
fix integer overflow check - json2tsv - JSON to TSV converter
git clone git://git.codemadness.org/json2tsv
Log
Files
Refs
README
LICENSE
---
commit 30c28c0ba7a3bec23f3c964f59aef85a9c2ba615
parent 79e73bfa51005f9b760c01117f4decce4435fe29
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 13 Oct 2019 14:51:50 +0200
fix integer overflow check
Diffstat:
M json2tsv.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/json2tsv.c b/json2tsv.c
@@ -81,17 +81,21 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc)
char *newp;
/* check addition overflow */
- need = cur + inc;
- if (cur > SIZE_MAX - need || *sz > SIZE_MAX - 16384) {
+ if (cur > SIZE_MAX - inc) {
errno = EOVERFLOW;
return -1;
}
+ need = cur + inc;
- if (*sz == 0 || need > *sz) {
- for (newsiz = *sz; newsiz < need; newsiz += 16384)
- ;
+ if (need > *sz) {
+ if (need > SIZE_MAX - 16384) {
+ newsiz = SIZE_MAX;
+ } else {
+ for (newsiz = *sz; newsiz < need; newsiz += 16384)
+ ;
+ }
if (!(newp = realloc(*value, newsiz)))
- return -1; /* up to caller to free memory */
+ return -1; /* up to caller to free *value */
*value = newp;
*sz = newsiz;
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.