Changeset 1072


Ignore:
Timestamp:
Jul 30, 2003, 3:41:48 PM (17 years ago)
Author:
sveta
Message:
  • Size limit (SIZE_MAX) for vector is added.
Location:
to-imperative/trunk/library/Vector
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Vector/vector.cc

    r1045 r1072  
    11#include <rf_core.hh>
    22#include <rf_types.hh>
     3#include <stdint.h>
    34
    45using namespace rfrt;
     
    1617  Expr expr;
    1718  vector_meaning(_source, expr);
    18   _vector = Expr (new rftype::Vector(expr, expr.get_len()));
     19  size_t length = expr.get_len();
     20  if (length > SIZE_MAX)
     21    RF_LIB_ERROR("Size limit exceeded");
     22  _vector = Expr (new rftype::Vector(expr, length));
    1923
    2024RF_END
  • to-imperative/trunk/library/Vector/vector_init.cc

    r1040 r1072  
    11#include <rf_core.hh>
    22#include <rf_types.hh>
     3#include <stdint.h>
    34
    45using namespace rfrt;
     
    1314
    1415RF_FUNC (Vector_m_Init, (RF_ARG _vector, _length, _fill), ())
    15 
     16 
    1617  if (_vector.get_len() == 1) {
    1718    Term* p_vector = _vector.get_first();
     
    2324    if (!len)
    2425      RF_LIB_ERROR("Invalid argument");
    25     else
    26       v-> vector_init(len->to_int(), _fill);
     26    else {
     27      size_t l = len->to_int();
     28      if (l > SIZE_MAX)
     29        RF_LIB_ERROR("Size limit exceeded"); 
     30      v-> vector_init(l, _fill);
     31    }
    2732  } else
    2833      RF_LIB_ERROR("Invalid argument");
  • to-imperative/trunk/library/Vector/vector_ref.cc

    r1043 r1072  
    2323    if (!number)
    2424      RF_LIB_ERROR("Invalid argument");
    25     else
    26       _exp = (*v)[number->to_int()];
     25    else {
     26      size_t n = number->to_int();
     27      if (n > v->get_length())
     28        RF_LIB_ERROR("Index out of range");
     29      _exp = (*v)[n];
     30    }
    2731  } else
    2832      RF_LIB_ERROR("Invalid argument");
  • to-imperative/trunk/library/Vector/vector_replace.cc

    r1045 r1072  
    11#include <rf_core.hh>
    22#include <rf_types.hh>
     3#include <stdint.h>
    34
    45using namespace rfrt;
     
    2122    Expr expr_vector;
    2223    vector_meaning(_source, expr_vector);
    23     p_vector->vector_replace(expr_vector.get_len(), expr_vector);
     24    size_t len = expr_vector.get_len();
     25    if (len > SIZE_MAX)
     26      RF_LIB_ERROR("Size limit exceeded");
     27    p_vector->vector_replace(len, expr_vector);
    2428  } else
    2529    RF_LIB_ERROR("Invalid argument");
Note: See TracChangeset for help on using the changeset viewer.