PVS-StudioWarnings

PVS-Studio warning V668 for icu

Nov 12th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. ChoiceFormat::operator=(const ChoiceFormat& that)
  2. {
  3.   ....
  4.   fChoiceLimits = (double*)
  5.     uprv_malloc( sizeof(double) * fCount);
  6.   fClosures = (UBool*) uprv_malloc( sizeof(UBool) * fCount);
  7.   fChoiceFormats = new UnicodeString[fCount];
  8.  
  9.   // check for memory allocation error
  10.   if (!fChoiceLimits || !fClosures || !fChoiceFormats)
  11.   {
  12.     if (fChoiceLimits) {
  13.       uprv_free(fChoiceLimits);
  14.       fChoiceLimits = NULL;
  15.     }
  16.     if (fClosures) {
  17.       uprv_free(fClosures);
  18.       fClosures = NULL;
  19.     }
  20.     if (fChoiceFormats) {
  21.       delete[] fChoiceFormats;
  22.       fChoiceFormats = NULL;
  23.     }
  24.   }
  25.   ....
  26. }
  27.  
  28. This suspicious code was found in icu project by PVS-Studio static code analyzer.
  29. Warning message is:
  30. V668 There is no sense in testing the 'fChoiceFormats' pointer against null, as the memory was allocated using the 'new' operator. The exception will be generated in the case of memory allocation error. choicfmt.cpp 177
  31.  
  32. 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