summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-09-11 14:27:57 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-09-11 14:34:05 +0200
commit033bb0382354cdebec8262b54b0539a4b69d56f6 (patch)
tree2a5f6a618a160e04612d82d1e7c60c5549ef743a /extensions
parentb30932fc55ed0dc14184c7015043fc42d5f274d6 (diff)
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
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/scanner/sane.cxx9
1 files changed, 8 insertions, 1 deletions
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 );