Skip to content

Commit f2736c3

Browse files
committed
Fix small stack problem on some ARM.
1 parent 13f337c commit f2736c3

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

unittest/sql/mf_iocache-t.cc

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ void sql_print_error(const char *format, ...)
9696

9797
/*** end of encryption tweaks and stubs ****************************/
9898

99-
PRAGMA_DISABLE_CHECK_STACK_FRAME
10099

101100
static IO_CACHE info;
102101
#define CACHE_SIZE 16384
@@ -118,8 +117,8 @@ int data_bad(const uchar *buf, size_t len)
118117
void temp_io_cache()
119118
{
120119
int res;
121-
uchar buf[CACHE_SIZE + 200];
122-
memset(buf, FILL, sizeof(buf));
120+
uchar *buf= (uchar *)malloc(CACHE_SIZE + 200);
121+
memset(buf, FILL, CACHE_SIZE + 200);
123122

124123
diag("temp io_cache with%s encryption", encrypt_tmp_files?"":"out");
125124

@@ -131,13 +130,13 @@ void temp_io_cache()
131130
res= my_b_write(&info, buf, 100);
132131
ok(res == 0 && info.pos_in_file == 0, "small write" INFO_TAIL );
133132

134-
res= my_b_write(&info, buf, sizeof(buf));
133+
res= my_b_write(&info, buf, CACHE_SIZE + 200);
135134
ok(res == 0 && info.pos_in_file == CACHE_SIZE, "large write" INFO_TAIL);
136135

137136
res= reinit_io_cache(&info, WRITE_CACHE, 250, 0, 0);
138137
ok(res == 0, "reinit with rewind" INFO_TAIL);
139138

140-
res= my_b_write(&info, buf, sizeof(buf));
139+
res= my_b_write(&info, buf, CACHE_SIZE + 200);
141140
ok(res == 0, "large write" INFO_TAIL);
142141

143142
res= my_b_flush_io_cache(&info, 1);
@@ -153,16 +152,17 @@ void temp_io_cache()
153152
res= my_b_read(&info, buf, 50) || data_bad(buf, 50);
154153
ok(res == 0 && info.pos_in_file == 0, "small read" INFO_TAIL);
155154

156-
res= my_b_read(&info, buf, sizeof(buf)) || data_bad(buf, sizeof(buf));
155+
res= my_b_read(&info, buf, CACHE_SIZE + 200) || data_bad(buf, CACHE_SIZE + 200);
157156
ok(res == 0 && info.pos_in_file == CACHE_SIZE, "large read" INFO_TAIL);
158157

159158
close_cached_file(&info);
159+
free(buf);
160160
}
161161

162162
void mdev9044()
163163
{
164164
int res;
165-
uchar buf[CACHE_SIZE + 200];
165+
uchar *buf= (uchar *)malloc(CACHE_SIZE + 200);
166166

167167
diag("MDEV-9044 Binlog corruption in Galera");
168168

@@ -190,10 +190,11 @@ void mdev9044()
190190
res= reinit_io_cache(&info, READ_CACHE, 0, 0, 0);
191191
ok(res == 0, "reinit READ_CACHE" INFO_TAIL);
192192

193-
res= my_b_read(&info, buf, sizeof(buf));
193+
res= my_b_read(&info, buf, CACHE_SIZE + 200);
194194
ok(res == 1 && strcmp((char*)buf, "second write") == 0, "read '%s'", buf);
195195

196196
close_cached_file(&info);
197+
free(buf);
197198
}
198199

199200
/* 2 Reads (with my_b_fill) in cache makes second read to fail */
@@ -294,20 +295,23 @@ void mdev14014()
294295
close_cached_file(&info);
295296
}
296297

298+
#define BUFF_SIZE17133 (1024*256)
297299
void mdev17133()
298300
{
299301
my_off_t res;
300302
int k;
301303
const int eof_iter=4, read_iter= 4;
302-
uchar buf_i[1024*256]; // read
303-
uchar buf_o[sizeof(buf_i)]; // write
304-
const size_t eof_block_size= sizeof(buf_o) / eof_iter;
304+
// read
305+
uchar *buf_i= (uchar *)malloc(BUFF_SIZE17133);
306+
// write
307+
uchar *buf_o= (uchar *)malloc(BUFF_SIZE17133);
308+
const size_t eof_block_size= BUFF_SIZE17133 / eof_iter;
305309
const size_t read_size= eof_block_size / read_iter;
306310
size_t total;
307311

308312
srand((uint) time(NULL));
309-
memset(buf_i, 0, sizeof( buf_i));
310-
memset(buf_o, FILL, sizeof(buf_o));
313+
memset(buf_i, 0, BUFF_SIZE17133);
314+
memset(buf_o, FILL, BUFF_SIZE17133);
311315

312316
diag("MDEV-17133 Dump thread reads from the past");
313317

@@ -316,10 +320,10 @@ void mdev17133()
316320
res= open_cached_file(&info, 0, 0, CACHE_SIZE, 0);
317321
ok(res == 0, "open_cached_file" INFO_TAIL);
318322

319-
res= my_b_write(&info, buf_o, sizeof(buf_o));
323+
res= my_b_write(&info, buf_o, BUFF_SIZE17133);
320324
ok(res == 0, "buffer is written" INFO_TAIL);
321325
res= my_b_tell(&info);
322-
ok(res == sizeof(buf_o), "cache size as expected");
326+
ok(res == BUFF_SIZE17133, "cache size as expected");
323327

324328
res= my_b_flush_io_cache(&info, 1);
325329
ok(res == 0, "flush" INFO_TAIL);
@@ -332,8 +336,8 @@ void mdev17133()
332336
int i;
333337
size_t curr_read_size;
334338
info.end_of_file=
335-
k == 1 ? sizeof(buf_o) :
336-
MY_MIN(sizeof(buf_o),
339+
k == 1 ? BUFF_SIZE17133 :
340+
MY_MIN(BUFF_SIZE17133,
337341
info.end_of_file + eof_block_size +
338342
// plus 25% of block for randomization to the average
339343
eof_block_size/4 - rand() % (eof_block_size/2));
@@ -342,7 +346,7 @@ void mdev17133()
342346
// the last block completes the current chunk
343347
for (i= 0; i < read_iter; i++, total += curr_read_size)
344348
{
345-
char buf_check[eof_block_size];
349+
char *buf_check= (char *)malloc(eof_block_size);
346350
size_t a,b;
347351

348352
a= (size_t)(info.end_of_file - total);
@@ -368,29 +372,33 @@ void mdev17133()
368372
memset(buf_check, FILL, curr_read_size);
369373
ok(memcmp(buf_i + total, buf_check, curr_read_size) == 0,
370374
"read correct data");
375+
free(buf_check);
371376
}
372377
ok(info.pos_in_file + (info.read_end - info.buffer) == info.end_of_file,
373378
"cache is read up to eof");
374379
ok(total == info.end_of_file, "total matches eof");
375380
}
376-
ok(total == sizeof(buf_i), "read total size match");
377-
ok(buf_i[sizeof(buf_i) - 1] == FILL, "data read correctly");
381+
ok(total == BUFF_SIZE17133, "read total size match");
382+
ok(buf_i[BUFF_SIZE17133 - 1] == FILL, "data read correctly");
378383

379384
close_cached_file(&info);
385+
free(buf_i);
386+
free(buf_o);
380387
}
381388

382389

390+
#define BUFF_SIZE10963 (1024*512)
383391
void mdev10963()
384392
{
385393
int res;
386394
uint n_checks= 8;
387-
uchar buf[1024 * 512];
388-
uint n_frag= sizeof(buf)/(2 * CACHE_SIZE);
395+
uchar *buf= (uchar *)malloc(BUFF_SIZE10963);
396+
uint n_frag= BUFF_SIZE10963/(2 * CACHE_SIZE);
389397
FILE *file;
390398
myf my_flags= MYF(MY_WME);
391399
const char *file_name="cache.log";
392400

393-
memset(buf, FILL, sizeof(buf));
401+
memset(buf, FILL, BUFF_SIZE10963);
394402
diag("MDEV-10963 Fragmented BINLOG query");
395403

396404
init_io_cache_encryption();
@@ -399,10 +407,10 @@ void mdev10963()
399407
/* copying source */
400408
res= open_cached_file(&info, 0, 0, CACHE_SIZE, 0);
401409
ok(res == 0, "open_cached_file" INFO_TAIL);
402-
res= my_b_write(&info, buf, sizeof(buf));
410+
res= my_b_write(&info, buf, BUFF_SIZE10963);
403411

404412
ulonglong total_size= my_b_tell(&info);
405-
ok(res == 0 && total_size == sizeof(buf), "cache is written");
413+
ok(res == 0 && total_size == BUFF_SIZE10963, "cache is written");
406414

407415
/* destination */
408416
file= my_fopen(file_name, O_RDWR | O_TRUNC | O_CREAT, my_flags);
@@ -436,15 +444,16 @@ void mdev10963()
436444
*/
437445
res= my_b_copy_to_file(&info, file, (size_t) total_size - copied_size);
438446
ok(res == 0, "%llu of the cache copied to file", total_size - copied_size);
439-
ok(my_ftell(file, my_flags) == sizeof(buf),
447+
ok(my_ftell(file, my_flags) == BUFF_SIZE10963,
440448
"file written in %d fragments", n_frag+1);
441449

442450
res= reinit_io_cache(&info, WRITE_CACHE, total_size, 0, 0);
443-
ok(res == 0 && my_b_tell(&info) == sizeof(buf), "cache turned to write");
451+
ok(res == 0 && my_b_tell(&info) == BUFF_SIZE10963, "cache turned to write");
444452
}
445453
close_cached_file(&info);
446454
my_fclose(file, my_flags);
447455
my_delete(file_name, MYF(MY_WME));
456+
free(buf);
448457
}
449458

450459
int main(int argc __attribute__((unused)),char *argv[])
@@ -474,4 +483,3 @@ int main(int argc __attribute__((unused)),char *argv[])
474483
return exit_status();
475484
}
476485

477-
PRAGMA_REENABLE_CHECK_STACK_FRAME

0 commit comments

Comments
 (0)