on master help sign in
Merge pull request #2005 from david-christiansen/ahmadsalim-testing/cstaticanalysis

Update Ahmad's cppcheck branch to work

commit6ba74da77aa30a956cd34d86e2c7c86c75631c4b authorDavid Christiansen <david@davidchristiansen.dk> dateFri 20 Mar 2015, 06:45 (12 years ago) parent48875995ed857b
2 files changed+12−2
.travis.yml+2 rts/idris_rts.c+10−2
.travis.yml+2
@@ -16,6 +16,7 @@ before_install:
1616 - sudo apt-get install hscolour
1717 # test dependency
1818 - sudo apt-get install -qq expect
19+ - sudo apt-get install -qq cppcheck
1920 - cabal install alex-3.1.3
2021install:
2122 - cabal install -f FFI --enable-tests --dependencies-only
@@ -30,6 +31,7 @@ script:
3031 - if [[ "$TESTS" != "doc" ]]; then cabal build; fi
3132 - if [[ "$TESTS" != "doc" ]]; then cabal copy; fi
3233 - if [[ "$TESTS" != "doc" ]]; then cabal register; fi
34+ - if [[ "$TESTS" == "test_c" ]]; then cppcheck -j 2 --error-exitcode=1 ./rts/idris_bitstring.c ./rts/idris_bitstring.h ./rts/idris_gc.h ./rts/idris_gc.c ./rts/idris_gmp.h ./rts/idris_gmp.c ./rts/idris_heap.h ./rts/idris_heap.c ./rts/idris_main.c ./rts/idris_net.h ./rts/idris_net.c ./rts/idris_opts.h ./rts/idris_opts.c ./rts/idris_rts.h ./rts/idris_rts.c ./rts/idris_stats.h ./rts/idris_stats.c ./rts/idris_stdfgn.h ./rts/idris_stdfgn.c ./rts/libtest.c ; fi
3335 - if [[ "$TESTS" == "test_llvm" ]]; then git clone --depth 1 https://github.com/idris-hackers/idris-llvm.git ; cd idris-llvm ; cabal install ; cd .. ; fi
3436 - make -j2 $TESTS
3537env:
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 */