PVS-StudioWarnings

PVS-Studio warning V621 for Putty

Nov 20th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #define snewn(n, type) ((type *)snmalloc((n), sizeof(type)))
  2.  
  3. void bareradioline(struct ctlpos *cp, int nacross, ...)
  4. {
  5.   va_list ap;
  6.   struct radio *buttons;
  7.   int i, nbuttons;
  8.  
  9.   va_start(ap, nacross);
  10.   nbuttons = 0;
  11.   while (1) {
  12.     char *btext = va_arg(ap, char *);
  13.     int bid;
  14.     if (!btext)
  15.       break;
  16.     bid = va_arg(ap, int);
  17.   }
  18.   va_end(ap);
  19.   buttons = snewn(nbuttons, struct radio);
  20.   va_start(ap, nacross);
  21.   for (i = 0; i < nbuttons; i++) {
  22.     buttons[i].text = va_arg(ap, char *);
  23.     buttons[i].id = va_arg(ap, int);
  24.   }
  25.   ....
  26. }
  27.  
  28. When operator for(;; ) begin work, the 'nbuttons' variable still equal zero.
  29.  
  30.  
  31. This suspicious code was found in Putty project by PVS-Studio static code analyzer.
  32. Warning message is:
  33. V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. winctrls.c 310
  34.  
  35. 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