Changeset 708


Ignore:
Timestamp:
May 1, 2003, 10:45:13 AM (18 years ago)
Author:
luba
Message:
  • Error is generated when the length of a number is more than the length

of UINTPTR_MAX.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Convert/to_int.cc

    r701 r708  
    1717
    1818RF_FUNC (To_m_Int, (RF_ARG e_Exp), (RF_RES s_Int))
    19   uint MAX_LEN = 10;
     19  uint LEN_SHORT_INT = 10;
    2020  uintptr_t len = 0;
    2121  int flag = 0;
     
    3838  for (; t < e_Exp.get_last(); t++) {
    3939    if (t->get_type() == type_char && ((Char*)t)->is_digit())
    40       if (len >= MAX_LEN - 1)
     40      if (len > UINTPTR_MAX - 1)
    4141        RF_LIB_ERROR("Argument too large for conversion");
    4242      else
     
    4646        if (((ShortInt*)t)->to_int() < 0)
    4747          retfail;
    48         else
    49           if (len >= MAX_LEN - ShortInt::get_char_len(((ShortInt*)t)->to_int()))
     48        else {
     49          size_t num_len = ShortInt::get_char_len(((ShortInt*)t)->to_int());
     50          if (len > UINTPTR_MAX - num_len)
    5051            RF_LIB_ERROR("Argument too large for conversion");
    5152          else
    52             len += ShortInt::get_char_len(((ShortInt*)t)->to_int());
     53            len += num_len;
     54        }
    5355      }
    5456#if 0
    5557    else
    5658    if (t->get_type() == type_word && ((Word*)t)->is_number())
    57       if (len >= MAX_LEN - длина слова ))
     59      if (len > UINTPTR_MAX - длина слова ))
    5860        RF_LIB_ERROR("Argument too large for conversion");
    5961      else
     
    6365      retfail;
    6466  };
     67
     68  if (len >= LEN_SHORT_INT)
     69    RF_LIB_ERROR("Argument too large for conversion");
     70
    6571  s_Int = ShortInt::create_expr(e_Exp, flag);
    6672
Note: See TracChangeset for help on using the changeset viewer.