Advertisement
PVS-StudioWarnings

PVS-Studio warning V510 for Scilab

Nov 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. typedef struct JavaVMOption {
  2.     char *optionString;
  3.     void *extraInfo;
  4. } JavaVMOption;
  5.  
  6. JavaVMOption *options;
  7.  
  8. BOOL startJVM(char *SCI_PATH)
  9. {
  10.   ....
  11.   fprintf(stderr, "%d: %s\n", j, vm_args.options[j]);
  12.   ....
  13. }
  14.  
  15. However, the fprintf() function will actually take an object of the JavaVMOption type as an argument. The code works only thanks to wonderful and lucky coincidence. Firstly, the 'optionString' member is located in the beginning of the structure. That's why it is this particular member that the fprintf() function will take and handle as a pointer to the string. Secondly, the function will not print anything after that, therefore no garbage will be printed too (i.e. the contents of the 'extraInfo' variable that will also get into the stack).
  16.  
  17. This suspicious code was found in Scilab project by PVS-Studio static code analyzer.
  18. Warning message is:
  19. V510 The 'fprintf' function is not expected to receive class-type variable as fourth actual argument. jvm.c 247
  20.  
  21. PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement