on master help sign in
Fix cppcheck error and make more robust

cppcheck now excludes imported library code from other projects and (for now) the Windows RTS. Everything also passes, so #1907 is superseded and fulfilled.

commite4358f0966f02242944f61b5197699d71b853d8b authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateMon 16 Mar 2015, 21:18 (12 years ago) parentb0c03c1
3 files changed+32−3
.travis.yml+1−1 cppcheck-targets+21 rts/idris_rts.c+10−2
.travis.yml+1−1
@@ -31,7 +31,7 @@ script:
3131 - if [[ "$TESTS" != "doc" ]]; then cabal build; fi
3232 - if [[ "$TESTS" != "doc" ]]; then cabal copy; fi
3333 - if [[ "$TESTS" != "doc" ]]; then cabal register; fi
34− - if [[ "$TESTS" == "test_c" ]]; then cppcheck -j 2 --enable=all --error-exitcode=1 ./rts/ ; fi
34+ - if [[ "$TESTS" == "test_c" ]]; then cppcheck -j 2 --enable=all --error-exitcode=1 --file-list=cppcheck-targets ; fi
3535 - if [[ "$TESTS" == "test_llvm" ]]; then git clone --depth 1 https://github.com/idris-hackers/idris-llvm.git ; cd idris-llvm ; cabal install ; cd .. ; fi
3636 - make -j2 $TESTS
3737env:
cppcheck-targetsnew file+21
@@ -0,0 +1,21 @@
1+./rts/idris_bitstring.c
2+./rts/idris_bitstring.h
3+./rts/idris_gc.h
4+./rts/idris_gc.c
5+./rts/idris_gmp.h
6+./rts/idris_gmp.c
7+./rts/idris_heap.h
8+./rts/idris_heap.c
9+./rts/idris_main.c
10+./rts/idris_net.h
11+./rts/idris_net.c
12+./rts/idris_opts.h
13+./rts/idris_opts.c
14+./rts/idris_rts.h
15+./rts/idris_rts.c
16+./rts/idris_stats.h
17+./rts/idris_stats.c
18+./rts/idris_stdfgn.h
19+./rts/idris_stdfgn.c
20+./rts/libtest.c
21+
rts/idris_rts.c+10−2
@@ -621,8 +621,16 @@ VAL idris_readStr(VM* vm, FILE* h) {
621621 {
622622 /* Make the buffer bigger and read more of the line */
623623 line_buf_size += BUFSIZE;
624− line_buf = (char *) realloc (line_buf, line_buf_size);
625−
624+ { /* limit the scope of new_line_buf to where it's needed for errors*/
625+ char *new_line_buf = realloc (line_buf, line_buf_size);
626+ if (new_line_buf == NULL)
627+ {
628+ fprintf(stderr, "Fatal Error: couldn't allocate a larger line buffer.");
629+ exit(EXIT_FAILURE);
630+ } else {
631+ line_buf = new_line_buf;
632+ }
633+ }
626634 /* points to last byte again */
627635 line_ptr = line_buf + line_buf_size - 1;
628636 /* so we can see if fgets put a 0 there */