Merge lp:~linuxjedi/libdrizzle/5.1-better-realloc into lp:libdrizzle
- 5.1-better-realloc
- Merge into libdrizzle-redux
Proposed by
Andrew Hutchings
Status: | Merged |
---|---|
Approved by: | Andrew Hutchings |
Approved revision: | 96 |
Merged at revision: | 94 |
Proposed branch: | lp:~linuxjedi/libdrizzle/5.1-better-realloc |
Merge into: | lp:libdrizzle |
Diff against target: |
468 lines (+77/-74) 8 files modified
libdrizzle/conn.cc (+7/-1) libdrizzle/field.cc (+2/-2) libdrizzle/result.cc (+8/-2) libdrizzle/row.cc (+3/-3) libdrizzle/statement.cc (+11/-10) libdrizzle/statement_local.h (+1/-1) libdrizzle/statement_param.cc (+39/-48) libdrizzle/structs.h (+6/-7) |
To merge this branch: | bzr merge lp:~linuxjedi/libdrizzle/5.1-better-realloc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Drizzle Trunk | Pending | ||
Review via email: mp+143306@code.launchpad.net |
Commit message
Description of the change
* Makes a few reallocs safer
* Removes reallocs where they aren't needed
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libdrizzle/conn.cc' |
2 | --- libdrizzle/conn.cc 2013-01-13 18:54:59 +0000 |
3 | +++ libdrizzle/conn.cc 2013-01-15 13:40:33 +0000 |
4 | @@ -1165,7 +1165,13 @@ |
5 | memmove(con->buffer, con->buffer_ptr, con->buffer_size); |
6 | } |
7 | con->buffer_allocation= con->buffer_allocation * 2; |
8 | - con->buffer= (unsigned char*)realloc(con->buffer, con->buffer_allocation); |
9 | + unsigned char *realloc_buffer= (unsigned char*)realloc(con->buffer, con->buffer_allocation); |
10 | + if (realloc_buffer == NULL) |
11 | + { |
12 | + drizzle_set_error(con, __func__, "realloc failure"); |
13 | + return DRIZZLE_RETURN_MEMORY; |
14 | + } |
15 | + con->buffer= realloc_buffer; |
16 | drizzle_log_debug(con, "buffer resized to: %zu", con->buffer_allocation); |
17 | con->buffer_ptr= con->buffer; |
18 | available_buffer= con->buffer_allocation - con->buffer_size; |
19 | |
20 | === modified file 'libdrizzle/field.cc' |
21 | --- libdrizzle/field.cc 2013-01-13 17:40:00 +0000 |
22 | +++ libdrizzle/field.cc 2013-01-15 13:40:33 +0000 |
23 | @@ -143,7 +143,7 @@ |
24 | |
25 | if (result->field_buffer == NULL) |
26 | { |
27 | - result->field_buffer= (drizzle_field_t)realloc(NULL, (*total) +1); |
28 | + result->field_buffer= new (std::nothrow) char[(*total) + 1]; |
29 | if (result->field_buffer == NULL) |
30 | { |
31 | drizzle_set_error(result->con, __func__, "Failed to allocate."); |
32 | @@ -176,7 +176,7 @@ |
33 | { |
34 | if (field) |
35 | { |
36 | - free(field); |
37 | + delete[] field; |
38 | } |
39 | } |
40 | |
41 | |
42 | === modified file 'libdrizzle/result.cc' |
43 | --- libdrizzle/result.cc 2013-01-13 22:31:54 +0000 |
44 | +++ libdrizzle/result.cc 2013-01-15 13:40:33 +0000 |
45 | @@ -327,9 +327,15 @@ |
46 | } |
47 | if (result->binary_rows) |
48 | { |
49 | - result->null_bitmap_list= (uint8_t**)realloc(result->null_bitmap_list, sizeof(uint8_t*) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE)); |
50 | + uint8_t **null_bitmap_list= (uint8_t**)realloc(result->null_bitmap_list, sizeof(uint8_t*) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE)); |
51 | + if (null_bitmap_list == NULL) |
52 | + { |
53 | + drizzle_row_free(result, row); |
54 | + drizzle_set_error(result->con, __func__, "Failed to realloc null_bitmap_list."); |
55 | + return DRIZZLE_RETURN_MEMORY; |
56 | + } |
57 | + result->null_bitmap_list= null_bitmap_list; |
58 | } |
59 | - |
60 | result->row_list= row_list; |
61 | |
62 | field_sizes_list= (size_t **)realloc(result->field_sizes_list, sizeof(size_t *) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE)); |
63 | |
64 | === modified file 'libdrizzle/row.cc' |
65 | --- libdrizzle/row.cc 2012-12-23 01:05:57 +0000 |
66 | +++ libdrizzle/row.cc 2013-01-15 13:40:33 +0000 |
67 | @@ -105,7 +105,7 @@ |
68 | return NULL; |
69 | } |
70 | |
71 | - result->row= (drizzle_row_t)realloc(NULL, (sizeof(drizzle_field_t) + sizeof(size_t)) * result->column_count); |
72 | + result->row= new (std::nothrow) drizzle_field_t[sizeof(size_t) * result->column_count]; |
73 | if (result->row == NULL) |
74 | { |
75 | drizzle_set_error(result->con, __func__, "Failed to allocate."); |
76 | @@ -126,7 +126,7 @@ |
77 | { |
78 | if (*ret_ptr != DRIZZLE_RETURN_IO_WAIT) |
79 | { |
80 | - free(result->row); |
81 | + delete[] result->row; |
82 | result->row= NULL; |
83 | result->field_sizes= NULL; |
84 | } |
85 | @@ -159,7 +159,7 @@ |
86 | drizzle_field_free(row[x]); |
87 | } |
88 | |
89 | - free(row); |
90 | + delete[] row; |
91 | } |
92 | |
93 | size_t *drizzle_row_field_sizes(drizzle_result_st *result) |
94 | |
95 | === modified file 'libdrizzle/statement.cc' |
96 | --- libdrizzle/statement.cc 2013-01-13 19:26:36 +0000 |
97 | +++ libdrizzle/statement.cc 2013-01-15 13:40:33 +0000 |
98 | @@ -416,6 +416,7 @@ |
99 | while((column= drizzle_column_next(stmt->execute_result))) |
100 | { |
101 | drizzle_bind_st *param= &stmt->result_params[column_counter]; |
102 | + param->type= column->type; |
103 | /* if this row is null in the result bitmap */ |
104 | if (*stmt->execute_result->null_bitmap & ((column_counter^2) << 2)) |
105 | { |
106 | @@ -433,9 +434,6 @@ |
107 | param->options.is_unsigned= true; |
108 | } |
109 | |
110 | - param->data= realloc(param->data, param->length); |
111 | - param->type= column->type; |
112 | - |
113 | switch(column->type) |
114 | { |
115 | case DRIZZLE_COLUMN_TYPE_NULL: |
116 | @@ -447,30 +445,37 @@ |
117 | break; |
118 | case DRIZZLE_COLUMN_TYPE_SHORT: |
119 | case DRIZZLE_COLUMN_TYPE_YEAR: |
120 | + param->data= param->data_buffer; |
121 | short_data= drizzle_get_byte2(row[column_counter]); |
122 | memcpy(param->data, &short_data, 2); |
123 | break; |
124 | case DRIZZLE_COLUMN_TYPE_INT24: |
125 | case DRIZZLE_COLUMN_TYPE_LONG: |
126 | + param->data= param->data_buffer; |
127 | long_data= drizzle_get_byte4(row[column_counter]); |
128 | memcpy(param->data, &long_data, 4); |
129 | break; |
130 | case DRIZZLE_COLUMN_TYPE_LONGLONG: |
131 | + param->data= param->data_buffer; |
132 | longlong_data= drizzle_get_byte8(row[column_counter]); |
133 | memcpy(param->data, &longlong_data, 8); |
134 | break; |
135 | case DRIZZLE_COLUMN_TYPE_FLOAT: |
136 | + param->data= param->data_buffer; |
137 | memcpy(param->data, row[column_counter], 4); |
138 | break; |
139 | case DRIZZLE_COLUMN_TYPE_DOUBLE: |
140 | + param->data= param->data_buffer; |
141 | memcpy(param->data, row[column_counter], 8); |
142 | break; |
143 | case DRIZZLE_COLUMN_TYPE_TIME: |
144 | + param->data= param->data_buffer; |
145 | drizzle_unpack_time(row[column_counter], param->length, (unsigned char*)param->data); |
146 | break; |
147 | case DRIZZLE_COLUMN_TYPE_DATE: |
148 | case DRIZZLE_COLUMN_TYPE_DATETIME: |
149 | case DRIZZLE_COLUMN_TYPE_TIMESTAMP: |
150 | + param->data= param->data_buffer; |
151 | drizzle_unpack_datetime(row[column_counter], param->length, (unsigned char*)param->data); |
152 | break; |
153 | case DRIZZLE_COLUMN_TYPE_TINY_BLOB: |
154 | @@ -483,7 +488,7 @@ |
155 | case DRIZZLE_COLUMN_TYPE_DECIMAL: |
156 | case DRIZZLE_COLUMN_TYPE_NEWDECIMAL: |
157 | case DRIZZLE_COLUMN_TYPE_NEWDATE: |
158 | - memcpy(param->data, row[column_counter], param->length); |
159 | + param->data= row[column_counter]; |
160 | break; |
161 | /* These types aren't handled yet, most are for older MySQL versions */ |
162 | case DRIZZLE_COLUMN_TYPE_VARCHAR: |
163 | @@ -547,18 +552,14 @@ |
164 | delete[] stmt->null_bitmap; |
165 | for (uint16_t x= 0; x < stmt->param_count; x++) |
166 | { |
167 | - if (stmt->query_params[x].options.is_allocated) |
168 | - { |
169 | - free(stmt->query_params[x].data); |
170 | - } |
171 | + delete[] stmt->query_params[x].data_buffer; |
172 | } |
173 | delete[] stmt->query_params; |
174 | if (stmt->execute_result) |
175 | { |
176 | for (uint16_t x= 0; x < stmt->execute_result->column_count; x++) |
177 | { |
178 | - free(stmt->result_params[x].data); |
179 | - free(stmt->result_params[x].converted_data); |
180 | + delete[] stmt->result_params[x].data_buffer; |
181 | } |
182 | delete[] stmt->result_params; |
183 | drizzle_result_free(stmt->execute_result); |
184 | |
185 | === modified file 'libdrizzle/statement_local.h' |
186 | --- libdrizzle/statement_local.h 2013-01-05 15:56:07 +0000 |
187 | +++ libdrizzle/statement_local.h 2013-01-15 13:40:33 +0000 |
188 | @@ -41,7 +41,7 @@ |
189 | extern "C" { |
190 | #endif |
191 | |
192 | -drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned, bool is_allocated); |
193 | +drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned); |
194 | |
195 | char *long_to_string(drizzle_bind_st *param, uint32_t val); |
196 | |
197 | |
198 | === modified file 'libdrizzle/statement_param.cc' |
199 | --- libdrizzle/statement_param.cc 2013-01-05 11:25:32 +0000 |
200 | +++ libdrizzle/statement_param.cc 2013-01-15 13:40:33 +0000 |
201 | @@ -39,7 +39,7 @@ |
202 | #include "libdrizzle/common.h" |
203 | |
204 | /* Internal function */ |
205 | -drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned, bool is_allocated) |
206 | +drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned) |
207 | { |
208 | if ((stmt == NULL) || (param_num >= stmt->param_count) || (data == NULL)) |
209 | { |
210 | @@ -55,7 +55,6 @@ |
211 | stmt->query_params[param_num].data= data; |
212 | stmt->query_params[param_num].length= length; |
213 | stmt->query_params[param_num].options.is_unsigned= is_unsigned; |
214 | - stmt->query_params[param_num].options.is_allocated= is_allocated; |
215 | stmt->query_params[param_num].is_bound= true; |
216 | |
217 | return DRIZZLE_RETURN_OK; |
218 | @@ -65,77 +64,70 @@ |
219 | drizzle_return_t drizzle_stmt_set_tiny(drizzle_stmt_st *stmt, uint16_t param_num, uint8_t value, bool is_unsigned) |
220 | { |
221 | uint8_t *val; |
222 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint8_t)); |
223 | - val= (uint8_t*) stmt->query_params[param_num].data; |
224 | + val= (uint8_t*) stmt->query_params[param_num].data_buffer; |
225 | *val= value; |
226 | |
227 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TINY, val, 1, is_unsigned, false); |
228 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TINY, val, 1, is_unsigned); |
229 | } |
230 | drizzle_return_t drizzle_stmt_set_short(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t value, bool is_unsigned) |
231 | { |
232 | uint16_t *val; |
233 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint16_t)); |
234 | - val= (uint16_t*) stmt->query_params[param_num].data; |
235 | + val= (uint16_t*) stmt->query_params[param_num].data_buffer; |
236 | *val= value; |
237 | |
238 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_SHORT, val, 2, is_unsigned, false); |
239 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_SHORT, val, 2, is_unsigned); |
240 | } |
241 | |
242 | drizzle_return_t drizzle_stmt_set_int(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t value, bool is_unsigned) |
243 | { |
244 | uint32_t *val; |
245 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint32_t)); |
246 | - val= (uint32_t*) stmt->query_params[param_num].data; |
247 | + val= (uint32_t*) stmt->query_params[param_num].data_buffer; |
248 | *val= value; |
249 | |
250 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONG, val, 4, is_unsigned, true); |
251 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONG, val, 4, is_unsigned); |
252 | } |
253 | |
254 | drizzle_return_t drizzle_stmt_set_bigint(drizzle_stmt_st *stmt, uint16_t param_num, uint64_t value, bool is_unsigned) |
255 | { |
256 | uint64_t *val; |
257 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint64_t)); |
258 | - val= (uint64_t*) stmt->query_params[param_num].data; |
259 | + val= (uint64_t*) stmt->query_params[param_num].data_buffer; |
260 | *val= value; |
261 | |
262 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONGLONG, val, 8, is_unsigned, false); |
263 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONGLONG, val, 8, is_unsigned); |
264 | } |
265 | |
266 | drizzle_return_t drizzle_stmt_set_double(drizzle_stmt_st *stmt, uint16_t param_num, double value) |
267 | { |
268 | double *val; |
269 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(double)); |
270 | - val= (double*) stmt->query_params[param_num].data; |
271 | + val= (double*) stmt->query_params[param_num].data_buffer; |
272 | *val= value; |
273 | |
274 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_DOUBLE, val, 8, false, false); |
275 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_DOUBLE, val, 8, false); |
276 | } |
277 | |
278 | drizzle_return_t drizzle_stmt_set_float(drizzle_stmt_st *stmt, uint16_t param_num, float value) |
279 | { |
280 | float *val; |
281 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(float)); |
282 | - val= (float*) stmt->query_params[param_num].data; |
283 | + val= (float*) stmt->query_params[param_num].data_buffer; |
284 | *val= value; |
285 | |
286 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_FLOAT, val, 4, false, false); |
287 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_FLOAT, val, 4, false); |
288 | } |
289 | |
290 | drizzle_return_t drizzle_stmt_set_string(drizzle_stmt_st *stmt, uint16_t param_num, char *value, size_t length) |
291 | { |
292 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_STRING, value, length, false, false); |
293 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_STRING, value, length, false); |
294 | } |
295 | |
296 | drizzle_return_t drizzle_stmt_set_null(drizzle_stmt_st *stmt, uint16_t param_num) |
297 | { |
298 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_NULL, NULL, 0, false, false); |
299 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_NULL, NULL, 0, false); |
300 | } |
301 | |
302 | drizzle_return_t drizzle_stmt_set_time(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds, bool is_negative) |
303 | { |
304 | drizzle_datetime_st *time; |
305 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(drizzle_datetime_st)); |
306 | - time= (drizzle_datetime_st*) stmt->query_params[param_num].data; |
307 | + time= (drizzle_datetime_st*) stmt->query_params[param_num].data_buffer; |
308 | |
309 | time->negative= is_negative; |
310 | time->day= days; |
311 | @@ -145,14 +137,13 @@ |
312 | time->microsecond= microseconds; |
313 | |
314 | /* Length not important because we will figure that out when packing */ |
315 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, time, 0, false, true); |
316 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, time, 0, false); |
317 | } |
318 | |
319 | drizzle_return_t drizzle_stmt_set_timestamp(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t year, uint8_t month, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds) |
320 | { |
321 | drizzle_datetime_st *timestamp; |
322 | - stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(drizzle_datetime_st)); |
323 | - timestamp= (drizzle_datetime_st*) stmt->query_params[param_num].data; |
324 | + timestamp= (drizzle_datetime_st*) stmt->query_params[param_num].data_buffer; |
325 | |
326 | timestamp->negative= false; |
327 | timestamp->year= year; |
328 | @@ -165,7 +156,7 @@ |
329 | timestamp->microsecond= microseconds; |
330 | |
331 | /* Length not important because we will figure that out when packing */ |
332 | - return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, timestamp, 0, false, true); |
333 | + return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, timestamp, 0, false); |
334 | } |
335 | |
336 | bool drizzle_stmt_get_is_null_from_name(drizzle_stmt_st *stmt, const char *column_name, drizzle_return_t *ret_ptr) |
337 | @@ -582,70 +573,70 @@ |
338 | |
339 | char *long_to_string(drizzle_bind_st *param, uint32_t val) |
340 | { |
341 | - /* Max length is -INT32_MAX + NUL = 12 */ |
342 | - param->converted_data= (char*)realloc(param->converted_data, 12); |
343 | + /* Pick an empty point in the buffer to make the str */ |
344 | + char* buffer= param->data_buffer + 50; |
345 | if (param->options.is_unsigned) |
346 | { |
347 | - snprintf(param->converted_data, 12, "%"PRIu32, val); |
348 | + snprintf(buffer, 12, "%"PRIu32, val); |
349 | } |
350 | else |
351 | { |
352 | - snprintf(param->converted_data, 12, "%"PRId32, (int32_t)val); |
353 | + snprintf(buffer, 12, "%"PRId32, (int32_t)val); |
354 | } |
355 | - return param->converted_data; |
356 | + return buffer; |
357 | } |
358 | |
359 | char *longlong_to_string(drizzle_bind_st *param, uint64_t val) |
360 | { |
361 | /* Max length is -INT64_MAX + NUL = 21 */ |
362 | - param->converted_data= (char*)realloc(param->converted_data, 21); |
363 | + char* buffer= param->data_buffer + 50; |
364 | if (param->options.is_unsigned) |
365 | { |
366 | - snprintf(param->converted_data, 21, "%"PRIu64, val); |
367 | + snprintf(buffer, 21, "%"PRIu64, val); |
368 | } |
369 | else |
370 | { |
371 | - snprintf(param->converted_data, 21, "%"PRId64, (int64_t)val); |
372 | + snprintf(buffer, 21, "%"PRId64, (int64_t)val); |
373 | } |
374 | - return param->converted_data; |
375 | + return buffer; |
376 | } |
377 | |
378 | char *double_to_string(drizzle_bind_st *param, double val) |
379 | { |
380 | /* Max length is 23 */ |
381 | - param->converted_data= (char*)realloc(param->converted_data, 23); |
382 | - snprintf(param->converted_data, 23, "%f", val); |
383 | - return param->converted_data; |
384 | + char* buffer= param->data_buffer + 50; |
385 | + snprintf(buffer, 23, "%f", val); |
386 | + return buffer; |
387 | } |
388 | |
389 | char *time_to_string(drizzle_bind_st *param, drizzle_datetime_st *time) |
390 | { |
391 | /* Max time is -HHH:MM:SS.ssssss + NUL = 17 */ |
392 | - param->converted_data= (char*)realloc(param->converted_data, 17); |
393 | + char* buffer= param->data_buffer + 50; |
394 | if (time->microsecond == 0) |
395 | { |
396 | - snprintf(param->converted_data, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8, (time->negative) ? "-" : "", time->hour, time->minute, time->second); |
397 | + snprintf(buffer, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8, (time->negative) ? "-" : "", time->hour, time->minute, time->second); |
398 | } |
399 | else |
400 | { |
401 | - snprintf(param->converted_data, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, (time->negative) ? "-" : "", time->hour, time->minute, time->second, time->microsecond); |
402 | + snprintf(buffer, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, (time->negative) ? "-" : "", time->hour, time->minute, time->second, time->microsecond); |
403 | } |
404 | - return param->converted_data; |
405 | + return buffer; |
406 | } |
407 | |
408 | char *timestamp_to_string(drizzle_bind_st *param, drizzle_datetime_st *timestamp) |
409 | { |
410 | /* Max timestamp is YYYY-MM-DD HH:MM:SS.ssssss + NUL = 26 */ |
411 | - param->converted_data= (char*)realloc(param->converted_data, 26); |
412 | + char* buffer= param->data_buffer + 50; |
413 | if (timestamp->microsecond == 0) |
414 | { |
415 | - snprintf(param->converted_data, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second); |
416 | + snprintf(buffer, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second); |
417 | } |
418 | else |
419 | { |
420 | - snprintf(param->converted_data, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second, timestamp->microsecond); |
421 | + snprintf(buffer, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second, timestamp->microsecond); |
422 | } |
423 | - return param->converted_data; |
424 | + return buffer; |
425 | } |
426 | |
427 | uint16_t drizzle_stmt_column_lookup(drizzle_result_st *result, const char *column_name, drizzle_return_t *ret_ptr) |
428 | |
429 | === modified file 'libdrizzle/structs.h' |
430 | --- libdrizzle/structs.h 2013-01-13 22:31:54 +0000 |
431 | +++ libdrizzle/structs.h 2013-01-15 13:40:33 +0000 |
432 | @@ -456,30 +456,29 @@ |
433 | { |
434 | drizzle_column_type_t type; |
435 | void *data; |
436 | + char *data_buffer; |
437 | uint32_t length; |
438 | bool is_bound; |
439 | - char *converted_data; |
440 | struct options_t |
441 | { |
442 | bool is_null; |
443 | bool is_unsigned; |
444 | bool is_long_data; |
445 | - bool is_allocated; |
446 | |
447 | options_t() : |
448 | is_null(false), |
449 | is_unsigned(false), |
450 | - is_long_data(false), |
451 | - is_allocated(false) |
452 | + is_long_data(false) |
453 | { } |
454 | } options; |
455 | drizzle_bind_st() : |
456 | type(DRIZZLE_COLUMN_TYPE_NONE), |
457 | data(NULL), |
458 | length(0), |
459 | - is_bound(false), |
460 | - converted_data(NULL) |
461 | - { } |
462 | + is_bound(false) |
463 | + { |
464 | + data_buffer= new (std::nothrow) char[128]; |
465 | + } |
466 | }; |
467 | |
468 | #ifdef __cplusplus |