~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_strfunc.cc

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
873
873
  String *res  = args[0]->val_str(str);
874
874
  /* must be int64_t to avoid truncation */
875
875
  int64_t start= args[1]->val_int();
876
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
 
876
  /* Assumes that the maximum length of a String is < INT32_MAX. */
877
877
  /* Limit so that code sees out-of-bound value properly. */
878
 
  int64_t length= arg_count == 3 ? args[2]->val_int() : INT_MAX32;
 
878
  int64_t length= arg_count == 3 ? args[2]->val_int() : INT32_MAX;
879
879
  int64_t tmp_length;
880
880
 
881
881
  if ((null_value=(args[0]->null_value || args[1]->null_value ||
887
887
      (length == 0 || !args[2]->unsigned_flag))
888
888
    return &my_empty_string;
889
889
 
890
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
 
890
  /* Assumes that the maximum length of a String is < INT32_MAX. */
891
891
  /* Set here so that rest of code sees out-of-bound value as such. */
892
 
  if ((length <= 0) || (length > INT_MAX32))
893
 
    length= INT_MAX32;
 
892
  if ((length <= 0) || (length > INT32_MAX))
 
893
    length= INT32_MAX;
894
894
 
895
895
  /* if "unsigned_flag" is set, we have a *huge* positive number. */
896
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
897
 
  if ((!args[1]->unsigned_flag && (start < INT_MIN32 || start > INT_MAX32)) ||
898
 
      (args[1]->unsigned_flag && ((uint64_t) start > INT_MAX32)))
 
896
  /* Assumes that the maximum length of a String is < INT32_MAX. */
 
897
  if ((!args[1]->unsigned_flag && (start < INT32_MIN || start > INT32_MAX)) ||
 
898
      (args[1]->unsigned_flag && ((uint64_t) start > INT32_MAX)))
899
899
    return &my_empty_string;
900
900
 
901
901
  start= ((start < 0) ? res->numchars() + start : start - 1);
1868
1868
    /* must be int64_t to avoid truncation */
1869
1869
    int64_t count= args[1]->val_int();
1870
1870
 
1871
 
    /* Assumes that the maximum length of a String is < INT_MAX32. */
 
1871
    /* Assumes that the maximum length of a String is < INT32_MAX. */
1872
1872
    /* Set here so that rest of code sees out-of-bound value as such. */
1873
 
    if (count > INT_MAX32)
1874
 
      count= INT_MAX32;
 
1873
    if (count > INT32_MAX)
 
1874
      count= INT32_MAX;
1875
1875
 
1876
1876
    uint64_t max_result_length= (uint64_t) args[0]->max_length * count;
1877
1877
    if (max_result_length >= MAX_BLOB_WIDTH)
1909
1909
  if (count <= 0 && (count == 0 || !args[1]->unsigned_flag))
1910
1910
    return &my_empty_string;
1911
1911
 
1912
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
 
1912
  /* Assumes that the maximum length of a String is < INT32_MAX. */
1913
1913
  /* Bounds check on count:  If this is triggered, we will error. */
1914
 
  if ((uint64_t) count > INT_MAX32)
1915
 
    count= INT_MAX32;
 
1914
  if ((uint64_t) count > INT32_MAX)
 
1915
    count= INT32_MAX;
1916
1916
  if (count == 1)                       // To avoid reallocs
1917
1917
    return res;
1918
1918
  length=res->length();
1956
1956
    {
1957
1957
      uint64_t temp= (uint64_t) args[1]->val_int();
1958
1958
 
1959
 
      /* Assumes that the maximum length of a String is < INT_MAX32. */
 
1959
      /* Assumes that the maximum length of a String is < INT32_MAX. */
1960
1960
      /* Set here so that rest of code sees out-of-bound value as such. */
1961
 
      if (temp > INT_MAX32)
1962
 
        temp = INT_MAX32;
 
1961
      if (temp > INT32_MAX)
 
1962
        temp = INT32_MAX;
1963
1963
 
1964
1964
      length= temp * collation.collation->mbmaxlen;
1965
1965
    }
1995
1995
      ((count < 0) && !args[1]->unsigned_flag))
1996
1996
    goto err;
1997
1997
  null_value=0;
1998
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
 
1998
  /* Assumes that the maximum length of a String is < INT32_MAX. */
1999
1999
  /* Set here so that rest of code sees out-of-bound value as such. */
2000
 
  if ((uint64_t) count > INT_MAX32)
2001
 
    count= INT_MAX32;
 
2000
  if ((uint64_t) count > INT32_MAX)
 
2001
    count= INT32_MAX;
2002
2002
  if (count <= (res_char_length= res->numchars()))
2003
2003
  {                                             // String to pad is big enough
2004
2004
    res->length(res->charpos((int) count));     // Shorten result if longer
2059
2059
    {
2060
2060
      uint64_t temp= (uint64_t) args[1]->val_int();
2061
2061
 
2062
 
      /* Assumes that the maximum length of a String is < INT_MAX32. */
 
2062
      /* Assumes that the maximum length of a String is < INT32_MAX. */
2063
2063
      /* Set here so that rest of code sees out-of-bound value as such. */
2064
 
      if (temp > INT_MAX32)
2065
 
        temp= INT_MAX32;
 
2064
      if (temp > INT32_MAX)
 
2065
        temp= INT32_MAX;
2066
2066
 
2067
2067
      length= temp * collation.collation->mbmaxlen;
2068
2068
    }
2096
2096
      ((count < 0) && !args[1]->unsigned_flag))
2097
2097
    goto err;  
2098
2098
  null_value=0;
2099
 
  /* Assumes that the maximum length of a String is < INT_MAX32. */
 
2099
  /* Assumes that the maximum length of a String is < INT32_MAX. */
2100
2100
  /* Set here so that rest of code sees out-of-bound value as such. */
2101
 
  if ((uint64_t) count > INT_MAX32)
2102
 
    count= INT_MAX32;
 
2101
  if ((uint64_t) count > INT32_MAX)
 
2102
    count= INT32_MAX;
2103
2103
 
2104
2104
  res_char_length= res->numchars();
2105
2105
 
2366
2366
        args[0]->result_type() == DECIMAL_RESULT)
2367
2367
    {
2368
2368
      double val= args[0]->val_real();
2369
 
      if ((val <= (double) LONGLONG_MIN) || 
2370
 
          (val >= (double) (uint64_t) ULONGLONG_MAX))
 
2369
      if ((val <= (double) INT64_MIN) || 
 
2370
          (val >= (double) (uint64_t) UINT64_MAX))
2371
2371
        dec=  ~(int64_t) 0;
2372
2372
      else
2373
2373
        dec= (uint64_t) (val + (val > 0 ? 0.5 : -0.5));