GraphicsMagick: 2 new changesets

GraphicsMagick Commits <[email protected]> Sun, 27 Oct 2024 09:11:21 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.30369.1730038298.8001.graphicsmagick-commit@lists.sourceforge.net>
changeset b1c2a72f3188 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=b1c2a72f3188
summary: Magick++/lib/Image.cpp: Remove debug print

changeset a4134210603a in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=a4134210603a
summary: Changes due to adding test programs to Coverity and Clang scan-build.

diffstat:

 ChangeLog                              |   43 ++++
 Magick++/Makefile.am                   |   10 +-
 Magick++/lib/Exception.cpp             |  316 ++++++++++++++++++++------------
 Magick++/lib/Image.cpp                 |    9 +-
 Magick++/lib/Magick++/Exception.h      |   20 +-
 Magick++/lib/Magick++/Image.h          |    5 +-
 Magick++/lib/Magick++/STL.h            |    6 +-
 Magick++/tests/attributes.cpp          |   10 +-
 Magick++/tests/readWriteImages.cpp     |    2 +-
 Makefile.am                            |    6 +-
 Makefile.in                            |    8 +-
 VisualMagick/installer/inc/version.isx |    4 +-
 magick/version.h                       |    4 +-
 tests/bitstream.c                      |   48 ++++-
 tests/constitute.c                     |    6 +-
 tests/rwblob.c                         |   10 +-
 tests/rwfile.c                         |   25 +-
 wand/wandtest.c                        |   16 +-
 www/ChangeLog.html                     |   33 +++
 www/Magick++/Image.html                |  290 +++++++++++++++--------------
 www/Magick++/Image.rst                 |   17 +
 21 files changed, 564 insertions(+), 324 deletions(-)

diffs (truncated from 1722 to 500 lines):

diff -r 8c40f4de550f -r a4134210603a ChangeLog
--- a/ChangeLog	Thu Oct 24 16:15:41 2024 -0500
+++ b/ChangeLog	Sun Oct 27 09:10:59 2024 -0500
@@ -1,3 +1,46 @@
+2024-10-27  Bob Friesenhahn  <[email protected]>
+
+	* tests/bitstream.c: Fixes so that 'test' mode allocates the
+	correct amount of memory for 31 and 32 bit depth.
+
+	* Makefile.am (coverity): Added tests programs to Coverity
+	analysis.
+	(scan-build): Added tests programs to Clang scan-build.
+
+	* Magick++/lib/Image.cpp (Magick::Image::formatExpressionRef): New
+	method which works the same as formatExpression, except that it
+	passes the argument by reference.
+
+	* wand/wandtest.c: Use secure buffer management.
+
+	* tests/constitute.c: Use secure buffer management.
+
+	* tests/rwfile.c: Use secure buffer management.
+
+	* tests/rwblob.c: Use secure buffer management.
+
+	* Magick++/lib/Magick++/STL.h (coderInfoList): Assure that
+	exception is always thrown when 'coder_list' is NULL.  Coverity
+	446809 "Dereference after null check".
+
+	* Magick++/lib/Exception.cpp (Magick::throwExceptionAlways): New
+	exception throwing helper function which always throws an
+	exception.
+
+	* tests/bitstream.c: Check range of arguments. Coverity 446805
+	"Untrusted loop bound".
+
+	* Magick++/tests/readWriteImages.cpp (main): Report columns()
+	rather than rows(). Coverity 446803 "Copy-paste error.
+
+	* Magick++/tests/attributes.cpp: Use new
+	formatExpressionRef(). Coverity 446808.
+
+	* Magick++/lib/Image.cpp (Magick::Image::formatExpressionRef): New
+	method to replace use of formatExpression(). The declaration of
+	formatExpression() should have passed the argument by reference.
+	Coverity 446808.
+
 2024-10-24  Bob Friesenhahn  <[email protected]>
 
 	* Magick++/tests/*: Updated to use InitializeMagickSentinel.
diff -r 8c40f4de550f -r a4134210603a Magick++/Makefile.am
--- a/Magick++/Makefile.am	Thu Oct 24 16:15:41 2024 -0500
+++ b/Magick++/Makefile.am	Sun Oct 27 09:10:59 2024 -0500
@@ -1,7 +1,7 @@
 #
 # Top Makefile for Magick++
 #
-# Copyright (C) 1999-2014 Bob Friesenhahn
+# Copyright (C) 1999-2024 Bob Friesenhahn
 #
 
 #AM_CPPFLAGS += -I$(top_srcdir)/Magick++/lib
@@ -19,10 +19,10 @@
 MAGICKPP_INCHEADERS = $(MAGICKPP_INCHEADERS_OPT)
 MAGICKPP_XFAIL_TESTS =
 else
-LIBMAGICKPP = 
-MAGICKPP_CHECK_PGRMS = 
-MAGICKPP_MANS = 
-MAGICKPP_PKGCONFIG = 
+LIBMAGICKPP =
+MAGICKPP_CHECK_PGRMS =
+MAGICKPP_MANS =
+MAGICKPP_PKGCONFIG =
 MAGICKPP_SCRPTS =
 MAGICKPP_TESTS =
 MAGICKPP_TOP_INCHEADERS =
diff -r 8c40f4de550f -r a4134210603a Magick++/lib/Exception.cpp
--- a/Magick++/lib/Exception.cpp	Thu Oct 24 16:15:41 2024 -0500
+++ b/Magick++/lib/Exception.cpp	Sun Oct 27 09:10:59 2024 -0500
@@ -1,6 +1,6 @@
 // This may look like C code, but it is really -*- C++ -*-
 //
-// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
+// Copyright Bob Friesenhahn, 1999-2024
 //
 // Implementation of Exception and derived classes
 //
@@ -420,31 +420,133 @@
 {
 }
 
-// Format and throw exception
-MagickDLLDecl void Magick::throwExceptionExplicit( const ExceptionType severity_,
-                                                   const char* reason_,
-                                                   const char* description_)
+namespace Magick
+{
+  //
+
+  // Throw appropriate C++ exception with type matching 'severity_' using pre-formatted 'message_'
+#if __cplusplus >= 201103L
+[[ noreturn ]]
+#endif
+  static void throwExceptionWithMessage( const ExceptionType severity_,
+                                         const std::string &message_ );
+
+  // Format ExceptionInfo into a message string
+  static std::string FormatExceptionInfoToMessage( const ExceptionInfo &exception_ );
+
+} // namespace Magick
+
+// Throw appropriate C++ exception with type matching 'severity_' using pre-formatted 'message_'
+#if __cplusplus >= 201103L
+[[ noreturn ]]
+#endif
+static void Magick::throwExceptionWithMessage( const ExceptionType severity_,
+                                               const std::string &message_ )
 {
-  // Just return if there is no reported error
-  if ( severity_ == UndefinedException )
-    return;
-
-  ExceptionInfo exception;
-
-  GetExceptionInfo( &exception );
-  ThrowException2( &exception, severity_, reason_, description_ );
-  throwException( exception );
+  switch ( severity_ )
+    {
+      // Warnings
+    case ResourceLimitWarning :
+      throw WarningResourceLimit( message_ );
+    case TypeWarning :
+      throw WarningType( message_ );
+    case OptionWarning :
+      throw WarningOption( message_ );
+    case DelegateWarning :
+      throw WarningDelegate( message_ );
+    case MissingDelegateWarning :
+      throw WarningMissingDelegate( message_ );
+    case CorruptImageWarning :
+      throw WarningCorruptImage( message_ );
+    case FileOpenWarning :
+      throw WarningFileOpen( message_ );
+    case BlobWarning :
+      throw WarningBlob ( message_ );
+    case StreamWarning :
+      throw WarningStream ( message_ );
+    case CacheWarning :
+      throw WarningCache ( message_ );
+    case CoderWarning :
+      throw WarningCoder ( message_ );
+    case ModuleWarning :
+      throw WarningModule( message_ );
+    case DrawWarning :
+      throw WarningDraw( message_ );
+    case ImageWarning :
+      throw WarningImage( message_ );
+    case XServerWarning :
+      throw WarningXServer( message_ );
+    case MonitorWarning :
+      throw WarningMonitor( message_ );
+    case RegistryWarning :
+      throw WarningRegistry( message_ );
+    case ConfigureWarning :
+      throw WarningConfigure( message_ );
+      // Errors
+    case ResourceLimitError :
+    case ResourceLimitFatalError :
+      throw ErrorResourceLimit( message_ );
+    case TypeError :
+    case TypeFatalError :
+      throw ErrorType( message_ );
+    case OptionError :
+    case OptionFatalError :
+      throw ErrorOption( message_ );
+    case DelegateError :
+    case DelegateFatalError :
+      throw ErrorDelegate( message_ );
+    case MissingDelegateError :
+    case MissingDelegateFatalError :
+      throw ErrorMissingDelegate( message_ );
+    case CorruptImageError :
+    case CorruptImageFatalError :
+      throw ErrorCorruptImage( message_ );
+    case FileOpenError :
+    case FileOpenFatalError :
+      throw ErrorFileOpen( message_ );
+    case BlobError :
+    case BlobFatalError :
+      throw ErrorBlob ( message_ );
+    case StreamError :
+    case StreamFatalError :
+      throw ErrorStream ( message_ );
+    case CacheError :
+    case CacheFatalError :
+      throw ErrorCache ( message_ );
+    case CoderError :
+    case CoderFatalError :
+      throw ErrorCoder ( message_ );
+    case ModuleError :
+    case ModuleFatalError :
+      throw ErrorModule ( message_ );
+    case DrawError :
+    case DrawFatalError :
+      throw ErrorDraw ( message_ );
+    case ImageError :
+    case ImageFatalError :
+      throw ErrorImage ( message_ );
+    case XServerError :
+    case XServerFatalError :
+      throw ErrorXServer ( message_ );
+    case MonitorError :
+    case MonitorFatalError :
+      throw ErrorMonitor ( message_ );
+    case RegistryError :
+    case RegistryFatalError :
+      throw ErrorRegistry ( message_ );
+    case ConfigureError :
+    case ConfigureFatalError :
+      throw ErrorConfigure ( message_ );
+    case UndefinedException :
+    default :
+      throw ErrorUndefined( message_ );
+    }
 }
 
-// Throw C++ exception, resetting exception argument to default state
-MagickDLLDecl void Magick::throwException( ExceptionInfo &exception_,
-                                           const bool quiet_)
+// Format ExceptionInfo into a message string for human consumption
+static std::string Magick::FormatExceptionInfoToMessage( const Magick::ExceptionInfo &exception_ )
 {
-  // Just return if there is no reported error
-  if ( exception_.severity == UndefinedException )
-    return;
-
-  // Format error message GraphicsMagick-style
+    // Format error message GraphicsMagick-style
   std::string message = SetClientName(0);
   if ( exception_.reason != 0 )
     {
@@ -465,109 +567,83 @@
           message += " (" + std::string(exception_.function) + ")";
     }
 
+  return message;
+}
+
+// Format and throw C++ exception (always) based on parameterized info.
+// Suitable for handling hard errors.
+#if __cplusplus >= 201103L
+[[ noreturn ]]
+#endif
+MagickDLLDecl void Magick::throwExceptionAlways( const ExceptionType severity_,
+                                                 const char* reason_,
+                                                 const char* description_)
+{
+  Magick::ExceptionInfo exception;
+
+  // Initialize the ExceptionInfo structure
+  GetExceptionInfo( &exception );
+
+  // Populate the ExceptionInfo structure
+  ThrowException2( &exception, severity_, reason_, description_ );
+
+  // Throw a C++ exception
+  // Format error message GraphicsMagick-style
+  std::string message = FormatExceptionInfoToMessage( exception );
+
+  // Release ExceptionInfo resources
+  DestroyExceptionInfo( &exception );
+
+  // Throw appropriate C++ exception with type matching 'severity_'
+  // using pre-formatted 'message_'
+  throwExceptionWithMessage(severity_, message );
+}
+
+// Format and throw C++ exception based on parameterized info if
+// severity_ is not UndefinedException.  This is used for both Warning
+// and Error cases.
+MagickDLLDecl void Magick::throwExceptionExplicit( const ExceptionType severity_,
+                                                   const char* reason_,
+                                                   const char* description_)
+{
+  // Just return if there is no reported error
+  if ( severity_ == UndefinedException )
+    return;
+
+  // Throw appropriate C++ exception with type matching 'severity_'
+  // using pre-formatted 'message_'
+  throwExceptionAlways(severity_, reason_, description_ );
+}
+
+// Throw C++ exception based on ExceptionInfo unless
+// exception_.severity is not UndefinedException or if quiet_ == true
+// and exception_.severity < ErrorException
+//
+// The exception_ argument is restored to the default state prior to
+// throwing C++ exception.
+MagickDLLDecl void Magick::throwException( ExceptionInfo &exception_,
+                                           const bool quiet_)
+{
+  // Just return if there is no reported error
+  if ( exception_.severity == UndefinedException )
+    return;
+
+  // Format error message GraphicsMagick-style
+  std::string message = FormatExceptionInfoToMessage( exception_ );
+
+  // Save severity
   ExceptionType severity = exception_.severity;
+
+  // Release ExceptionInfo resources
   DestroyExceptionInfo( &exception_ );
+
+  // Restore ExceptionInfo to defaults
   GetExceptionInfo( &exception_ );
 
   if ((quiet_) && (severity < ErrorException))
       return;
 
-  switch ( severity )
-    {
-      // Warnings
-    case ResourceLimitWarning :
-      throw WarningResourceLimit( message );
-    case TypeWarning :
-      throw WarningType( message );
-    case OptionWarning :
-      throw WarningOption( message );
-    case DelegateWarning :
-      throw WarningDelegate( message );
-    case MissingDelegateWarning :
-      throw WarningMissingDelegate( message );
-    case CorruptImageWarning :
-      throw WarningCorruptImage( message );
-    case FileOpenWarning :
-      throw WarningFileOpen( message );
-    case BlobWarning :
-      throw WarningBlob ( message );
-    case StreamWarning :
-      throw WarningStream ( message );
-    case CacheWarning :
-      throw WarningCache ( message );
-    case CoderWarning :
-      throw WarningCoder ( message );
-    case ModuleWarning :
-      throw WarningModule( message );
-    case DrawWarning :
-      throw WarningDraw( message );
-    case ImageWarning :
-      throw WarningImage( message );
-    case XServerWarning :
-      throw WarningXServer( message );
-    case MonitorWarning :
-      throw WarningMonitor( message );
-    case RegistryWarning :
-      throw WarningRegistry( message );
-    case ConfigureWarning :
-      throw WarningConfigure( message );
-      // Errors
-    case ResourceLimitError :
-    case ResourceLimitFatalError :
-      throw ErrorResourceLimit( message );
-    case TypeError :
-    case TypeFatalError :
-      throw ErrorType( message );
-    case OptionError :
-    case OptionFatalError :
-      throw ErrorOption( message );
-    case DelegateError :
-    case DelegateFatalError :
-      throw ErrorDelegate( message );
-    case MissingDelegateError :
-    case MissingDelegateFatalError :
-      throw ErrorMissingDelegate( message );
-    case CorruptImageError :
-    case CorruptImageFatalError :
-      throw ErrorCorruptImage( message );
-    case FileOpenError :
-    case FileOpenFatalError :
-      throw ErrorFileOpen( message );
-    case BlobError :
-    case BlobFatalError :
-      throw ErrorBlob ( message );
-    case StreamError :
-    case StreamFatalError :
-      throw ErrorStream ( message );
-    case CacheError :
-    case CacheFatalError :
-      throw ErrorCache ( message );
-    case CoderError :
-    case CoderFatalError :
-      throw ErrorCoder ( message );
-    case ModuleError :
-    case ModuleFatalError :
-      throw ErrorModule ( message );
-    case DrawError :
-    case DrawFatalError :
-      throw ErrorDraw ( message );
-    case ImageError :
-    case ImageFatalError :
-      throw ErrorImage ( message );
-    case XServerError :
-    case XServerFatalError :
-      throw ErrorXServer ( message );
-    case MonitorError :
-    case MonitorFatalError :
-      throw ErrorMonitor ( message );
-    case RegistryError :
-    case RegistryFatalError :
-      throw ErrorRegistry ( message );
-    case ConfigureError :
-    case ConfigureFatalError :
-      throw ErrorConfigure ( message );
-    case UndefinedException :
-    default :
-      throw ErrorUndefined( message );
-    }
+  // Throw appropriate C++ exception with type matching 'severity_'
+  // using pre-formatted 'message_'
+  throwExceptionWithMessage(severity, message );
 }
diff -r 8c40f4de550f -r a4134210603a Magick++/lib/Image.cpp
--- a/Magick++/lib/Image.cpp	Thu Oct 24 16:15:41 2024 -0500
+++ b/Magick++/lib/Image.cpp	Sun Oct 27 09:10:59 2024 -0500
@@ -2970,7 +2970,9 @@
 // Format the specified expression similar to command line '-format'.
 // For example "%wx%h" is converted to a string containing image
 // WIDTHxHEIGHT like "640x480".
-std::string Magick::Image::formatExpression ( const std::string expression )
+//
+// The original interface definition "formatExpression" failed to pass by value!
+std::string Magick::Image::formatExpressionRef ( const std::string &expression )
 {
   // TranslateText throws exceptions into Image.
   modifyImage();
@@ -2987,6 +2989,10 @@
   throwImageException( image( )->exception );
   return translated_str;
 }
+std::string Magick::Image::formatExpression ( const std::string expression ) // deprecated
+{
+  return Magick::Image::formatExpressionRef( expression );
+}
 
 // Gamma adjustment
 double Magick::Image::gamma ( void ) const
@@ -4249,7 +4255,6 @@
   if (magick_initialized)
     {
       magick_initialized=false;
-      fprintf(stderr, "Destroying Magick...\n");
       MagickLib::DestroyMagick();
     }
 }
diff -r 8c40f4de550f -r a4134210603a Magick++/lib/Magick++/Exception.h
--- a/Magick++/lib/Magick++/Exception.h	Thu Oct 24 16:15:41 2024 -0500
+++ b/Magick++/lib/Magick++/Exception.h	Sun Oct 27 09:10:59 2024 -0500
@@ -1,6 +1,6 @@
 // This may look like C code, but it is really -*- C++ -*-
 //
-// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
+// Copyright Bob Friesenhahn, 1999-2024
 //
 // Definition of Magick::Exception and derived classes
 // Magick::Warning* and Magick::Error*.  Derived from C++ STD
@@ -322,13 +322,27 @@
   //
   // No user-serviceable components beyond this point.
   //
+  // Format and throw C++ exception (always) based on parameterized info.
+  // Suitable for handling hard errors.
+#if __cplusplus >= 201103L
+[[ noreturn ]]
+#endif
+  MagickDLLDeclExtern void throwExceptionAlways( const ExceptionType severity_,
+                                                 const char* reason_,
+                                                 const char* description_ = 0);
 
-  // Throw exception based on raw data
+  // Format and throw C++ exception based on parameterized info if
+  // severity_ is not UndefinedException.
   MagickDLLDeclExtern void throwExceptionExplicit( const MagickLib::ExceptionType severity_,
                                                    const char* reason_,
                                                    const char* description_ = 0 );
 
-  // Throw exception based on ImageMagick's ExceptionInfo
+  // Throw C++ exception based on ExceptionInfo unless
+  // exception_.severity is not UndefinedException or if quiet_ ==
+  // true and exception_.severity < ErrorException
+  //
+  // The exception_ argument is restored to the default state prior to
+  // throwing C++ exception.
   MagickDLLDeclExtern void throwException( MagickLib::ExceptionInfo &exception_,
                                            const bool quiet_ = false );
 
diff -r 8c40f4de550f -r a4134210603a Magick++/lib/Magick++/Image.h