~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.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:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
 
22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/int64_t.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
27
 
#include "drizzled/internal/my_sys.h"
28
 
 
29
 
#include <math.h>
30
 
 
31
 
#include <algorithm>
32
 
 
33
 
using namespace std;
34
 
 
35
 
namespace drizzled
36
 
{
 
27
 
37
28
 
38
29
/****************************************************************************
39
30
 Field type int64_t int (8 bytes)
45
36
  char *end;
46
37
  uint64_t tmp;
47
38
 
48
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
49
 
 
50
39
  tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
51
40
  if (error == MY_ERRNO_ERANGE)
52
41
  {
75
64
  int error= 0;
76
65
  int64_t res;
77
66
 
78
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
79
 
 
80
67
  nr= rint(nr);
81
68
 
82
69
  if (nr <= (double) INT64_MIN)
111
98
{
112
99
  int error= 0;
113
100
 
114
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
115
 
 
116
101
#ifdef WORDS_BIGENDIAN
117
102
  if (table->s->db_low_byte_first)
118
103
  {
128
113
double Field_int64_t::val_real(void)
129
114
{
130
115
  int64_t j;
131
 
 
132
 
  ASSERT_COLUMN_MARKED_FOR_READ;
133
 
 
134
116
#ifdef WORDS_BIGENDIAN
135
117
  if (table->s->db_low_byte_first)
136
118
  {
147
129
int64_t Field_int64_t::val_int(void)
148
130
{
149
131
  int64_t j;
150
 
 
151
 
  ASSERT_COLUMN_MARKED_FOR_READ;
152
 
 
153
132
#ifdef WORDS_BIGENDIAN
154
133
  if (table->s->db_low_byte_first)
155
134
    j=sint8korr(ptr);
165
144
{
166
145
  const CHARSET_INFO * const cs= &my_charset_bin;
167
146
  uint32_t length;
168
 
  uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
 
147
  uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
169
148
  val_buffer->alloc(mlength);
170
149
  char *to=(char*) val_buffer->ptr();
171
150
  int64_t j;
172
 
 
173
 
  ASSERT_COLUMN_MARKED_FOR_READ;
174
 
 
175
151
#ifdef WORDS_BIGENDIAN
176
152
  if (table->s->db_low_byte_first)
177
153
    j=sint8korr(ptr);
291
267
  return from + sizeof(val);
292
268
}
293
269
 
294
 
} /* namespace drizzled */