Skip to content

Commit

Permalink
Eliminate VLAs for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
fundamental authored and JohannesLorenz committed Oct 21, 2023
1 parent 87e2d94 commit c26251c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int assert_hex_eq(const char *a, const char *b, size_t size_a, size_t size_b,
//create difference mask
const int longer = size_a > size_b ? size_a : size_b;
const int shorter = size_a < size_b ? size_a : size_b;
char mask[longer];
char *mask = (char*)malloc(longer);
memset(mask, 0, longer);
for(int i=0; i<shorter; ++i)
if(a[i] != b[i])
Expand All @@ -210,6 +210,7 @@ int assert_hex_eq(const char *a, const char *b, size_t size_a, size_t size_b,
printf("#\n");
printf("# Observed:\n");
hexdump(b, mask, size_b);
free(mask);

global_err++;
} else
Expand Down
15 changes: 8 additions & 7 deletions test/pretty-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "common.h"

rtosc_arg_val_t scanned[32];
#define BUF_LEN 256

/**
* @brief check_alt like check, but specify an alternative expectation
Expand All @@ -19,10 +20,10 @@ void check_alt(const char* arg_val_str, const rtosc_print_options* opt,
const char* tc_base, int line,
const char* _exp_print)
{
int tc_len = 256;
char tc_full[tc_len]; // descr. for full testcase name
int strbuflen = 256;
char strbuf[strbuflen];
const int tc_len = BUF_LEN;
char tc_full[BUF_LEN]; // descr. for full testcase name
int strbuflen = BUF_LEN;
char strbuf[BUF_LEN];
memset(strbuf, 0x7f, strbuflen); /* init with rubbish */

int num = rtosc_count_printed_arg_vals(arg_val_str);
Expand Down Expand Up @@ -451,8 +452,8 @@ void scan_ranges()

void fail_at_arg(const char* arg_val_str, int exp_fail, int line)
{
int tc_len = 256;
char tc_full[tc_len]; // descr. for full testcase name
const int tc_len = BUF_LEN;
char tc_full[BUF_LEN]; // descr. for full testcase name

int num = rtosc_count_printed_arg_vals(arg_val_str);

Expand Down Expand Up @@ -480,7 +481,7 @@ void messages()

num = rtosc_count_printed_arg_vals_of_msg(input);
assert_int_eq(3, num, "read a /noteOn message", __LINE__);
rtosc_arg_val_t scanned[num];
rtosc_arg_val_t scanned[3];
size_t rd = rtosc_scan_message(input, msgbuf, msgbuflen,
scanned, num,
strbuf, strbuflen);
Expand Down

0 comments on commit c26251c

Please sign in to comment.