Changeset 34 for trunk/src/slib.c


Ignore:
Timestamp:
May 19, 2006, 8:09:51 PM (18 years ago)
Author:
rainer
Message:

Code cleanup and minor fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/slib.c

    r29 r34  
    77#include <string.h>
    88#include <limits.h>
     9#ifdef HAVE_STDINT_H
     10/* for SIZE_MAX */
     11#include <stdint.h>
     12#endif
    913
    1014#include <unistd.h>
     
    25062510 * ---------------------------------------------------------------- */
    25072511
     2512#ifndef SIZE_MAX
     2513#define SIZE_MAX              (4294967295U)
     2514#endif
     2515
    25082516int sl_ok_muli (int a, int b) /* a*b */
    25092517{
    2510   if (a >= (INT_MIN / b) && a <= (INT_MAX / b))
     2518  if ((b == 0) || (a >= (INT_MIN / b) && a <= (INT_MAX / b)))
     2519    return SL_TRUE; /* no overflow */
     2520  return SL_FALSE;
     2521}
     2522
     2523int sl_ok_muls (size_t a, size_t b) /* a*b */
     2524{
     2525  if ((b == 0) || (a <= (SIZE_MAX / b)))
    25112526    return SL_TRUE; /* no overflow */
    25122527  return SL_FALSE;
     
    25402555}
    25412556
     2557int sl_ok_adds (size_t a, size_t b) /* a+b */
     2558{
     2559  if (a <= (SIZE_MAX - b))
     2560    return SL_TRUE; /* no overflow */
     2561  else
     2562    return SL_FALSE;
     2563}
     2564
    25422565int sl_ok_subi (int a, int b) /* a-b */
    25432566{
Note: See TracChangeset for help on using the changeset viewer.