Skip to content

Commit

Permalink
Fixed: [Reading in a file exactly the same size as the buffer could l…
Browse files Browse the repository at this point in the history
…eave the buffer not terminated with a 0 byte](#49)
  • Loading branch information
olofhagsand committed Jun 18, 2020
1 parent 4a3d949 commit f8048bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 4.6.0
Expected: July 2020

* Fixed: [Reading in a file exactly the same size as the buffer could leave the buffer not terminated with a 0 byte](https://github.com/clicon/cligen/pull/49)
* Refactored the CLIgen object and parsetree structure. The object
structure had a object-within-objct structure, where a CLIgen object
(cg_obj) contained a "parse-tree" object which in turn contains all
Expand Down
4 changes: 2 additions & 2 deletions cligen_syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ cligen_parse_file(cligen_handle h,

i = 0; /* position in buf */
while (1){ /* read the whole file */
if ((c = fgetc(f)) == EOF)
if ((c = fgetc(f)) == EOF)
break;
if (len==i){
if (i == len-1){
if ((buf = realloc(buf, 2*len)) == NULL){
fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno));
goto done;
Expand Down

0 comments on commit f8048bc

Please sign in to comment.