Avoid using strlen function in loop

This commit is contained in:
Jim Huang 2019-07-21 22:20:05 +08:00 committed by daan
parent 3e9c953eea
commit 28b874129a

View file

@ -214,10 +214,16 @@ static const char* mi_getenv(const char* name) {
#pragma warning(suppress:4996) #pragma warning(suppress:4996)
const char* s = getenv(name); const char* s = getenv(name);
if (s == NULL) { if (s == NULL) {
<<<<<<< HEAD
char buf[64+1]; char buf[64+1];
mi_strlcpy(buf,name,64); mi_strlcpy(buf,name,64);
for (size_t i = 0; i < strlen(buf); i++) { for (size_t i = 0; i < strlen(buf); i++) {
buf[i] = toupper(name[i]); buf[i] = toupper(name[i]);
=======
size_t buf_size = strlen(buf);
for (size_t i = 0; i < buf_size; i++) {
buf[i] = toupper(buf[i]);
>>>>>>> Avoid using strlen function in loop
} }
#pragma warning(suppress:4996) #pragma warning(suppress:4996)
s = getenv(buf); s = getenv(buf);
@ -234,7 +240,8 @@ static void mi_option_init(mi_option_desc_t* desc) {
const char* s = mi_getenv(buf); const char* s = mi_getenv(buf);
if (s != NULL) { if (s != NULL) {
mi_strlcpy(buf, s, sizeof(buf)); mi_strlcpy(buf, s, sizeof(buf));
for (size_t i = 0; i < strlen(buf); i++) { size_t buf_size = strlen(buf); // TODO: use strnlen?
for (size_t i = 0; i < buf_size; i++) {
buf[i] = toupper(buf[i]); buf[i] = toupper(buf[i]);
} }
if (buf[0]==0 || strstr("1;TRUE;YES;ON", buf) != NULL) { if (buf[0]==0 || strstr("1;TRUE;YES;ON", buf) != NULL) {