~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/extract.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:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include "drizzled/server_includes.h"
 
21
#include CSTDINT_H
22
22
#include "drizzled/temporal.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/session.h"
25
25
#include "drizzled/calendar.h"
26
26
#include "drizzled/function/time/extract.h"
27
27
 
28
 
namespace drizzled
29
 
{
30
 
 
31
28
/*
32
29
   'interval_names' reflects the order of the enumeration interval_type.
33
30
   See item/time.h
70
67
  case INTERVAL_HOUR_MICROSECOND: max_length=13; date_value=0; break;
71
68
  case INTERVAL_MINUTE_MICROSECOND: max_length=11; date_value=0; break;
72
69
  case INTERVAL_SECOND_MICROSECOND: max_length=9; date_value=0; break;
73
 
  case INTERVAL_LAST: assert(0); break;
 
70
  case INTERVAL_LAST: assert(0); break; /* purecov: deadcode */
74
71
  }
75
72
}
76
73
 
86
83
  }
87
84
 
88
85
  /* We could have either a datetime or a time.. */
89
 
  DateTime datetime_temporal;
90
 
  Time time_temporal;
 
86
  drizzled::DateTime datetime_temporal;
 
87
  drizzled::Time time_temporal;
91
88
 
92
89
  /* Abstract pointer type we'll use in the final switch */
93
 
  Temporal *temporal;
 
90
  drizzled::Temporal *temporal;
94
91
 
95
92
  if (date_value)
96
93
  {
324
321
    case INTERVAL_LAST: 
325
322
    default:
326
323
        assert(0); 
327
 
        return 0;
 
324
        return 0;  /* purecov: deadcode */
328
325
  }
329
326
}
330
327
 
344
341
      return 0;
345
342
  return 1;
346
343
}
347
 
 
348
 
} /* namespace drizzled */