[Libreoffice-commits] core.git: extensions/source

Stephan Bergmann sbergman at redhat.com
Mon Sep 11 12:34:30 UTC 2017


 extensions/source/scanner/sane.cxx |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

New commits:
commit 033bb0382354cdebec8262b54b0539a4b69d56f6
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Sep 11 14:27:57 2017 +0200

    Make clamping of aParams.format work reliably
    
    ...regardless of the details of the type of aParams.format, SANE_Frame, which
    the SANE documentation at <http://sane.alioth.debian.org/html/doc012.html> is
    vague about.  (It could, e.g., validly have negative values in an implementation
    where SANE_Frame is an enum with additional, negative enumerators besides the
    required SAN_FRAME_GRAY...BLUE.)
    
    Before 2687a5aca143c53c364cb44993ca601b8dd1c65e "-Werror,-Wtautological-compare
    with latest clang" the code had explicitly checked for aParams.format < 0.
    
    Change-Id: Ie2a19e67e942841c5a52b862cb427bac77d6ebb2

diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index 80b6bb30f5c9..6d29d0a5670d 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <cstdarg>
+#include <type_traits>
 #include <math.h>
 #include <osl/file.h>
 #include <sal/log.hxx>
@@ -623,8 +624,14 @@ bool Sane::Start( BitmapTransporter& rBitmap )
                                   "SANE_FRAME_RED", "SANE_FRAME_GREEN",
                                   "SANE_FRAME_BLUE", "Unknown !!!" };
             fprintf( stderr, "Parameters for frame %d:\n", nStream );
-            if( aParams.format > 4 )
+            if( static_cast<
+                    typename std::make_unsigned<
+                        typename std::underlying_type<SANE_Frame>::type>::type>(
+                            aParams.format)
+                > 4 )
+            {
                 aParams.format = (SANE_Frame)5;
+            }
             fprintf( stderr, "format:           %s\n", ppFormats[ (int)aParams.format ] );
             fprintf( stderr, "last_frame:       %s\n", aParams.last_frame ? "TRUE" : "FALSE" );
             fprintf( stderr, "depth:            %d\n", (int)aParams.depth );


More information about the Libreoffice-commits mailing list