~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/unix_timestamp.cc

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
  if (! temporal.is_valid())
64
64
  {
65
65
    null_value= true;
66
 
    char buff[MAX_DATETIME_WIDTH];
 
66
    char buff[drizzled::DateTime::MAX_STRING_LENGTH];
67
67
    int buff_len;
68
 
    buff_len= temporal.to_string(buff, MAX_DATETIME_WIDTH);
69
 
    assert(buff_len < MAX_DATETIME_WIDTH);
70
 
    buff[buff_len]= '\0';
 
68
    buff_len= temporal.to_string(buff, drizzled::DateTime::MAX_STRING_LENGTH);
 
69
    assert((buff_len+1) < drizzled::DateTime::MAX_STRING_LENGTH);
71
70
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), buff);
72
71
    return 0;
73
72
  }