Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cbe8ed9

Browse filesBrowse files
committed
[core][WString] init stack arraies
1 parent 007d703 commit cbe8ed9
Copy full SHA for cbe8ed9

File tree

Expand file treeCollapse file tree

1 file changed

+14
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-12
lines changed

‎core/WString.cpp

Copy file name to clipboardExpand all lines: core/WString.cpp
+14-12Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ String::String(String &&rval)
7676
String::String(char c)
7777
{
7878
init();
79-
char buf[2];
79+
char buf[2] = {0};
8080
buf[0] = c;
8181
buf[1] = 0;
8282
*this = buf;
@@ -85,39 +85,39 @@ String::String(char c)
8585
String::String(unsigned char value, unsigned char base)
8686
{
8787
init();
88-
char buf[1 + 8 * sizeof(unsigned char)];
88+
char buf[1 + 8 * sizeof(unsigned char)] = {0};
8989
utoa(value, buf, base);
9090
*this = buf;
9191
}
9292

9393
String::String(int value, unsigned char base)
9494
{
9595
init();
96-
char buf[2 + 8 * sizeof(int)];
96+
char buf[2 + 8 * sizeof(int)] = {0};
9797
itoa(value, buf, base);
9898
*this = buf;
9999
}
100100

101101
String::String(unsigned int value, unsigned char base)
102102
{
103103
init();
104-
char buf[1 + 8 * sizeof(unsigned int)];
104+
char buf[1 + 8 * sizeof(unsigned int)] = {0};
105105
utoa(value, buf, base);
106106
*this = buf;
107107
}
108108

109109
String::String(long value, unsigned char base)
110110
{
111111
init();
112-
char buf[2 + 8 * sizeof(long)];
112+
char buf[2 + 8 * sizeof(long)] = {0};
113113
ltoa(value, buf, base);
114114
*this = buf;
115115
}
116116

117117
String::String(unsigned long value, unsigned char base)
118118
{
119119
init();
120-
char buf[1 + 8 * sizeof(unsigned long)];
120+
char buf[1 + 8 * sizeof(unsigned long)] = {0};
121121
ultoa(value, buf, base);
122122
*this = buf;
123123
}
@@ -126,6 +126,7 @@ String::String(float value, unsigned char decimalPlaces)
126126
{
127127
static size_t const FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
128128
char *buf = (char *)rt_malloc(FLOAT_BUF_SIZE);
129+
rt_memset(buf, 0, FLOAT_BUF_SIZE);
129130
init();
130131
decimalPlaces = min(decimalPlaces, FLT_MAX_DECIMAL_PLACES);
131132
*this = dtostrf(value, (decimalPlaces + 2U), decimalPlaces, buf);
@@ -136,6 +137,7 @@ String::String(double value, unsigned char decimalPlaces)
136137
{
137138
static size_t const DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
138139
char *buf = (char *)rt_malloc(DOUBLE_BUF_SIZE);
140+
rt_memset(buf, 0, DOUBLE_BUF_SIZE);
139141
init();
140142
decimalPlaces = min(decimalPlaces, DBL_MAX_DECIMAL_PLACES);
141143
*this = dtostrf(value, (decimalPlaces + 2U), decimalPlaces, buf);
@@ -295,35 +297,35 @@ bool String::concat(char c)
295297

296298
bool String::concat(unsigned char num)
297299
{
298-
char buf[1 + 3 * sizeof(unsigned char)];
300+
char buf[1 + 3 * sizeof(unsigned char)] = {0};
299301
itoa(num, buf, 10);
300302
return concat(buf);
301303
}
302304

303305
bool String::concat(int num)
304306
{
305-
char buf[2 + 3 * sizeof(int)];
307+
char buf[2 + 3 * sizeof(int)] = {0};
306308
itoa(num, buf, 10);
307309
return concat(buf);
308310
}
309311

310312
bool String::concat(unsigned int num)
311313
{
312-
char buf[1 + 3 * sizeof(unsigned int)];
314+
char buf[1 + 3 * sizeof(unsigned int)] = {0};
313315
utoa(num, buf, 10);
314316
return concat(buf);
315317
}
316318

317319
bool String::concat(long num)
318320
{
319-
char buf[2 + 3 * sizeof(long)];
321+
char buf[2 + 3 * sizeof(long)] = {0};
320322
ltoa(num, buf, 10);
321323
return concat(buf);
322324
}
323325

324326
bool String::concat(unsigned long num)
325327
{
326-
char buf[1 + 3 * sizeof(unsigned long)];
328+
char buf[1 + 3 * sizeof(unsigned long)] = {0};
327329
ultoa(num, buf, 10);
328330
return concat(buf);
329331
}
@@ -498,7 +500,7 @@ bool String::startsWith( const String &s2, unsigned int offset ) const
498500

499501
bool String::endsWith( const String &s2 ) const
500502
{
501-
if ( len < s2.len || !buffer || !s2.buffer) return false;
503+
if (len < s2.len || !buffer || !s2.buffer) return false;
502504
return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
503505
}
504506

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.