• unknown's avatar
    Bug#10963: LEFT/RIGHT/SUBSTR/.. string functions returns wrong result \ · 3a867382
    unknown authored
      on large length
      
    Problem:  Most (all) of the numeric inputs were being coerced into
    int (32 bit) sized variables.  Works OK for sane inputs; any input
    larger than 2^32 (or 2^31 for signed vars) exihibited predictable
    wrapping behavior (up to about 10^18) and then started having really
    strange behaviour past that point (since the conversion to 64 bit int
    from the DECIMAL type can do weird things on out of range numbers).
    
    Solution: 1)  Add many tests.  2)  Convert input from (u)long type to
    (u)longlong.  3)  Do (sometimes multiple) sanity checks on input,
    keeping in mind that sometimes a negative longlong is not a negative
    longlong (if the unsigned_flag is set).  4) Emulate existing behavior
    w/rt negative and "small" out-of-bounds values.
    
    
    mysql-test/r/func_str.result:
      Additional test results for #10963
    mysql-test/t/func_str.test:
      Additional test results for #10963
    sql/item_func.cc:
      Used larger type for counting, to avoid truncation.
    sql/item_strfunc.cc:
      Fix for #10963, including comments and cleaned up logic
    3a867382
item_strfunc.cc 83.4 KB