|
20 | 20 | #include "item.h"
|
21 | 21 | #include "sql_parse.h" // For check_stack_overrun
|
22 | 22 |
|
23 |
| -/* |
24 |
| - Allocating memory and *also* using it (reading and |
25 |
| - writing from it) because some build instructions cause |
26 |
| - compiler to optimize out stack_used_up. Since alloca() |
27 |
| - here depends on stack_used_up, it doesnt get executed |
28 |
| - correctly and causes json_debug_nonembedded to fail |
29 |
| - ( --error ER_STACK_OVERRUN_NEED_MORE does not occur). |
30 |
| -*/ |
31 |
| -#define ALLOCATE_MEM_ON_STACK(A) do \ |
32 |
| - { \ |
33 |
| - uchar *array= (uchar*)alloca(A); \ |
34 |
| - bzero(array, A); \ |
35 |
| - my_checksum(0, array, A); \ |
36 |
| - } while(0) |
| 23 | +#ifndef DBUG_OFF |
| 24 | +static int dbug_json_check_min_stack_requirement() |
| 25 | +{ |
| 26 | + my_error(ER_STACK_OVERRUN_NEED_MORE, MYF(ME_FATAL), |
| 27 | + my_thread_stack_size, my_thread_stack_size, STACK_MIN_SIZE); |
| 28 | + return 1; |
| 29 | +} |
| 30 | +#endif |
37 | 31 |
|
38 | 32 | /*
|
39 | 33 | Compare ASCII string against the string with the specified
|
@@ -151,11 +145,8 @@ int json_path_parts_compare(
|
151 | 145 | int res, res2;
|
152 | 146 |
|
153 | 147 | DBUG_EXECUTE_IF("json_check_min_stack_requirement",
|
154 |
| - { |
155 |
| - long arbitrary_var; |
156 |
| - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); |
157 |
| - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); |
158 |
| - }); |
| 148 | + return dbug_json_check_min_stack_requirement();); |
| 149 | + |
159 | 150 | if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))
|
160 | 151 | return 1;
|
161 | 152 |
|
@@ -1210,11 +1201,7 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
|
1210 | 1201 | json_engine_t loc_js;
|
1211 | 1202 | bool set_js;
|
1212 | 1203 | DBUG_EXECUTE_IF("json_check_min_stack_requirement",
|
1213 |
| - { |
1214 |
| - long arbitrary_var; |
1215 |
| - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); |
1216 |
| - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); |
1217 |
| - }); |
| 1204 | + return dbug_json_check_min_stack_requirement();); |
1218 | 1205 | if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))
|
1219 | 1206 | return 1;
|
1220 | 1207 |
|
@@ -2128,13 +2115,8 @@ String *Item_func_json_object::val_str(String *str)
|
2128 | 2115 |
|
2129 | 2116 | static int do_merge(String *str, json_engine_t *je1, json_engine_t *je2)
|
2130 | 2117 | {
|
2131 |
| - |
2132 | 2118 | DBUG_EXECUTE_IF("json_check_min_stack_requirement",
|
2133 |
| - { |
2134 |
| - long arbitrary_var; |
2135 |
| - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); |
2136 |
| - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); |
2137 |
| - }); |
| 2119 | + return dbug_json_check_min_stack_requirement();); |
2138 | 2120 | if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))
|
2139 | 2121 | return 1;
|
2140 | 2122 |
|
@@ -2471,11 +2453,7 @@ static int do_merge_patch(String *str, json_engine_t *je1, json_engine_t *je2,
|
2471 | 2453 | bool *empty_result)
|
2472 | 2454 | {
|
2473 | 2455 | DBUG_EXECUTE_IF("json_check_min_stack_requirement",
|
2474 |
| - { |
2475 |
| - long arbitrary_var; |
2476 |
| - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); |
2477 |
| - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); |
2478 |
| - }); |
| 2456 | + return dbug_json_check_min_stack_requirement();); |
2479 | 2457 | if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))
|
2480 | 2458 | return 1;
|
2481 | 2459 |
|
|
0 commit comments