Skip to content

Commit 6cb1a04

Browse files
tmediccicederom
authored andcommitted
system/irtest: Fix issues regarding portability and buffer size
This commit fixes issues regarding portability by using variables with fixed width (and their format macro constants). Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
1 parent 901278a commit 6cb1a04

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

system/irtest/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ config SYSTEM_IRTEST_MAX_NIRDEV
3232
default 2
3333

3434
config SYSTEM_IRTEST_MAX_SIRDATA
35-
int "The Maximum size of sending data in unsigned int"
35+
int "The Maximum size of sending data in nwords (4 bytes)"
3636
default 64
3737

3838
endif

system/irtest/cmd.cxx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ CMD1(close_device, size_t, index)
226226

227227
CMD1(write_data, size_t, index)
228228
{
229-
unsigned int data[CONFIG_SYSTEM_IRTEST_MAX_SIRDATA];
229+
uint32_t data[CONFIG_SYSTEM_IRTEST_MAX_SIRDATA];
230+
uint32_t tmp;
230231

231232
if (index >= CONFIG_SYSTEM_IRTEST_MAX_NIRDEV)
232233
{
@@ -236,7 +237,7 @@ CMD1(write_data, size_t, index)
236237
int size = 0;
237238
for (; size < CONFIG_SYSTEM_IRTEST_MAX_SIRDATA; size++)
238239
{
239-
unsigned int tmp = get_next_arg < unsigned int > ();
240+
tmp = get_next_arg < uint32_t > ();
240241
if (tmp == 0)
241242
{
242243
break;
@@ -250,14 +251,14 @@ CMD1(write_data, size_t, index)
250251
if (size % 2 == 0)
251252
{
252253
int result = write(g_irdevs[index], data,
253-
sizeof(unsigned int) * (size - 1));
254+
sizeof(uint32_t) * (size - 1));
254255
usleep(data[size - 1]);
255256
return result;
256257
}
257258
else
258259
{
259260
return write(g_irdevs[index], data,
260-
sizeof(unsigned int) * size);
261+
sizeof(uint32_t) * size);
261262
}
262263
}
263264

@@ -268,20 +269,20 @@ CMD2(read_data, size_t, index, size_t, size)
268269
return ERROR;
269270
}
270271

271-
unsigned int data[size];
272+
uint32_t data[size];
272273
int result = read(g_irdevs[index], data, sizeof(data));
273274
if (result > 0)
274275
{
275-
result /= sizeof(unsigned int);
276+
result /= sizeof(uint32_t);
276277
for (int i = 0; i < result; i++)
277278
{
278279
if (i + 1 == result)
279280
{
280-
printf("%d\n", data[i]);
281+
printf("%" PRIu32 "\n", data[i]);
281282
}
282283
else
283284
{
284-
printf("%d, ", data[i]);
285+
printf("%" PRIu32 ", ", data[i]);
285286
}
286287
}
287288
}

0 commit comments

Comments
 (0)