jdk/src/share/native/sun/awt/medialib/safe_alloc.h

Print this page
rev 5697 : 8001972: Improve image processing
Reviewed-by: prr, ahgross


  24  */
  25 
  26 #ifndef __SAFE_ALLOC_H__
  27 #define __SAFE_ALLOC_H__
  28 
  29 #include "j2d_md.h"
  30 
  31 /*
  32  * Macroses defined below are wrappers for alloc functions
  33  * that perform buffer size calculation with integer overflow
  34  * check.
  35  */
  36 #define SAFE_TO_ALLOC_2(c, sz)                                             \
  37     (((c) > 0) && ((sz) > 0) &&                                            \
  38      ((0xffffffffu / ((juint)(c))) > ((juint)(sz))))
  39 
  40 #define SAFE_TO_ALLOC_3(w, h, sz)                                          \
  41     (((w) > 0) && ((h) > 0) && ((sz) > 0) &&                               \
  42      (((0xffffffffu / ((juint)(w))) / ((juint)(h))) > ((juint)(sz))))
  43 





  44 
  45 #endif // __SAFE_ALLOC_H__


  24  */
  25 
  26 #ifndef __SAFE_ALLOC_H__
  27 #define __SAFE_ALLOC_H__
  28 
  29 #include "j2d_md.h"
  30 
  31 /*
  32  * Macroses defined below are wrappers for alloc functions
  33  * that perform buffer size calculation with integer overflow
  34  * check.
  35  */
  36 #define SAFE_TO_ALLOC_2(c, sz)                                             \
  37     (((c) > 0) && ((sz) > 0) &&                                            \
  38      ((0xffffffffu / ((juint)(c))) > ((juint)(sz))))
  39 
  40 #define SAFE_TO_ALLOC_3(w, h, sz)                                          \
  41     (((w) > 0) && ((h) > 0) && ((sz) > 0) &&                               \
  42      (((0xffffffffu / ((juint)(w))) / ((juint)(h))) > ((juint)(sz))))
  43 
  44 #define SAFE_TO_MULT(a, b) \
  45     (((a) > 0) && ((b) >= 0) && ((0x7fffffff / (a)) > (b)))
  46 
  47 #define SAFE_TO_ADD(a, b) \
  48     (((a) >= 0) && ((b) >= 0) && ((0x7fffffff - (a)) > (b)))
  49 
  50 #endif // __SAFE_ALLOC_H__