Skip to content

Commit 42c4a35

Browse files
committed
fix: fix uart && shell string buffer bugs
1 parent 6350b61 commit 42c4a35

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

project/raspberrypi4b/driver/src/raspberrypi4b_driver_at24cxx_interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ void at24cxx_interface_delay_ms(uint32_t ms)
155155
void at24cxx_interface_debug_print(const char *const fmt, ...)
156156
{
157157
char str[256];
158-
uint8_t len;
158+
uint16_t len;
159159
va_list args;
160160

161161
memset((char *)str, 0, sizeof(char) * 256);
162162
va_start(args, fmt);
163-
vsnprintf((char *)str, 256, (char const *)fmt, args);
163+
vsnprintf((char *)str, 255, (char const *)fmt, args);
164164
va_end(args);
165165

166166
len = strlen((char *)str);

project/raspberrypi4b/src/main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
6767
{"type", required_argument, NULL, 4},
6868
{NULL, 0, NULL, 0},
6969
};
70-
char type[32] = "unknow";
70+
char type[33] = "unknow";
7171
uint8_t data = rand() % 0xFF;
7272
uint16_t reg = 0x0000;
7373
at24cxx_t chip_type = AT24C01;
@@ -96,7 +96,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
9696
case 'h' :
9797
{
9898
/* set the type */
99-
memset(type, 0, sizeof(char) * 32);
99+
memset(type, 0, sizeof(char) * 33);
100100
snprintf(type, 32, "h");
101101

102102
break;
@@ -106,7 +106,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
106106
case 'i' :
107107
{
108108
/* set the type */
109-
memset(type, 0, sizeof(char) * 32);
109+
memset(type, 0, sizeof(char) * 33);
110110
snprintf(type, 32, "i");
111111

112112
break;
@@ -116,7 +116,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
116116
case 'p' :
117117
{
118118
/* set the type */
119-
memset(type, 0, sizeof(char) * 32);
119+
memset(type, 0, sizeof(char) * 33);
120120
snprintf(type, 32, "p");
121121

122122
break;
@@ -126,7 +126,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
126126
case 'e' :
127127
{
128128
/* set the type */
129-
memset(type, 0, sizeof(char) * 32);
129+
memset(type, 0, sizeof(char) * 33);
130130
snprintf(type, 32, "e_%s", optarg);
131131

132132
break;
@@ -136,7 +136,7 @@ uint8_t at24cxx(uint8_t argc, char **argv)
136136
case 't' :
137137
{
138138
/* set the type */
139-
memset(type, 0, sizeof(char) * 32);
139+
memset(type, 0, sizeof(char) * 33);
140140
snprintf(type, 32, "t_%s", optarg);
141141

142142
break;

project/stm32f407/EW/stm32f407.dep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<configuration>
66
<name>Release</name>
77
<outputs>
8-
<file>$PROJ_DIR$\..\usr\src\getopt.c</file>
9-
<file>$PROJ_DIR$\..\usr\src\stm32f4xx_it.c</file>
10-
<file>$PROJ_DIR$\..\usr\src\shell.c</file>
118
<file>$PROJ_DIR$\..\usr\src\main.c</file>
9+
<file>$PROJ_DIR$\..\usr\src\shell.c</file>
10+
<file>$PROJ_DIR$\..\usr\src\getopt.c</file>
1211
<file>$PROJ_DIR$\..\usr\src\stm32f4xx_hal_msp.c</file>
1312
<file>$PROJ_DIR$\..\usr\src\system_stm32f4xx.c</file>
13+
<file>$PROJ_DIR$\..\usr\src\stm32f4xx_it.c</file>
1414
</outputs>
1515
<forcedrebuild>
1616
<name>[REBUILD_ALL]</name>

project/stm32f407/driver/src/stm32f407_driver_at24cxx_interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ void at24cxx_interface_delay_ms(uint32_t ms)
147147
void at24cxx_interface_debug_print(const char *const fmt, ...)
148148
{
149149
char str[256];
150-
uint8_t len;
150+
uint16_t len;
151151
va_list args;
152152

153153
memset((char *)str, 0, sizeof(char) * 256);
154154
va_start(args, fmt);
155-
vsnprintf((char *)str, 256, (char const *)fmt, args);
155+
vsnprintf((char *)str, 255, (char const *)fmt, args);
156156
va_end(args);
157157

158158
len = strlen((char *)str);

project/stm32f407/interface/src/uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ uint16_t uart_flush(void)
203203
uint16_t uart_print(const char *const fmt, ...)
204204
{
205205
char str[256];
206-
uint8_t len;
206+
uint16_t len;
207207
va_list args;
208208

209209
/* print to the buffer */
210210
memset((char *)str, 0, sizeof(char) * 256);
211211
va_start(args, fmt);
212-
vsnprintf((char *)str, 256, (char const *)fmt, args);
212+
vsnprintf((char *)str, 255, (char const *)fmt, args);
213213
va_end(args);
214214

215215
/* send the data */

0 commit comments

Comments
 (0)