posva/catimg

Undefined behavior was detected in the source code.

TimJSwan89 opened this issue · 3 comments

catimg/src/stb_image.h:1571:24: error: The left operand in a bitwise left-shift is negative.
  Undefined behavior (UB-CEB4).
   see C11 section 6.5.7:4 http://rvdoc.org/C11/6.5.7
   see C11 section J.2:1 item 52 http://rvdoc.org/C11/J.2
   see CERT-C section INT13-C http://rvdoc.org/CERT-C/INT13-C
   see CERT-C section MSC15-C http://rvdoc.org/CERT-C/MSC15-C
   see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1
catimg/src/sh_image.c:4:0:
catimg/src/stb_image.h: In function ‘stbi__gif_load_next’:
catimg/src/stb_image.h:5752:84: warning: unused parameter ‘req_comp’ [-Wunused-parameter]
 static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp)
                                                                                    ^
catimg/src/sh_utils.c: In function ‘read_stdin’:
catimg/src/sh_utils.c:45:14: warning: implicit declaration of function ‘fileno’ [-Wimplicit-function-declaration]
     int fd = fileno(stdin);
              ^
catimg/src/catimg.c:127:9: error: Incompatible pointer types in assignment or function call arguments.
  Constraint violation (CV-TEAS2).
   see C11 section 6.5.16.1:1 http://rvdoc.org/C11/6.5.16.1
   see CERT-C section MSC40-C http://rvdoc.org/CERT-C/MSC40-C
   see MISRA-C section 8.1:1 http://rvdoc.org/MISRA-C/8.1
catimg/src/catimg.c: In function ‘main’:
catimg/src/catimg.c:138:21: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
                     usleep(img.delays[frame - 1] * 10000);
                     ^
catimg/src/sh_color.h:39:1: error: Identifier color_map declared with incompatible types in different translation units.
  Undefined behavior (UB-TIN1).
   see C11 section 6.2.7:2 http://rvdoc.org/C11/6.2.7
   see C11 section J.2:1 item 15 http://rvdoc.org/C11/J.2
   see CERT-C section DCL23-C http://rvdoc.org/CERT-C/DCL23-C
   see CERT-C section DCL40-C http://rvdoc.org/CERT-C/DCL40-C
   see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1
catimg/src/sh_color.h:39:1: error: Multiple external definitions for color_map.
  Undefined behavior (UB-TIN2).
   see C11 section 6.9:5 http://rvdoc.org/C11/6.9
   see C11 section J.2:1 item 84 http://rvdoc.org/C11/J.2
   see CERT-C section MSC15-C http://rvdoc.org/CERT-C/MSC15-C
   see MISRA-C section 8.5:1 http://rvdoc.org/MISRA-C/8.5
   see MISRA-C section 8.8:6 http://rvdoc.org/MISRA-C/8.8
   see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1
catimg/src/sh_color.h:41:1: error: Multiple external definitions for yuv_color_map.
  Undefined behavior (UB-TIN2).
   see C11 section 6.9:5 http://rvdoc.org/C11/6.9
   see C11 section J.2:1 item 84 http://rvdoc.org/C11/J.2
   see CERT-C section MSC15-C http://rvdoc.org/CERT-C/MSC15-C
   see MISRA-C section 8.5:1 http://rvdoc.org/MISRA-C/8.5
   see MISRA-C section 8.8:6 http://rvdoc.org/MISRA-C/8.8
   see MISRA-C section 8.1:3 http://rvdoc.org/MISRA-C/8.1
posva commented

Make sure you use cmake to compile catimg 🙂
It works correctly using latest clang

I was using cmake. However, I was analyzing your source code for behavior that is undefined according to the C standards. Your code may compile and work correctly in all human realizable test cases, however, to prove that it has certain properties in all possible cases, developers usually use the standard to create provable mathematical statements about their code. Please refer to the links provided in my report if you are interested in the standards that are broken in your code. Once you think that you corrected them, let me know and I will test them again if you desire.

posva commented

Ok, in that case, I'm open to contributions if anybody wants to fix those