Skip to content

Commit a57cdf1

Browse files
committed
Use sizeof() instead of strlen() where possible
1 parent 7e1c53b commit a57cdf1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/WebRequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ void AsyncWebServerRequest::requestAuthentication(AsyncAuthType method, const ch
10011001
case AsyncAuthType::AUTH_BASIC:
10021002
{
10031003
String header;
1004-
if (header.reserve(strlen(T_BASIC_REALM) + strlen(realm) + 1)) {
1004+
if (header.reserve(sizeof(T_BASIC_REALM) - 1 + strlen(realm) + 1)) {
10051005
header.concat(T_BASIC_REALM);
10061006
header.concat(realm);
10071007
header.concat('"');
@@ -1015,7 +1015,7 @@ void AsyncWebServerRequest::requestAuthentication(AsyncAuthType method, const ch
10151015
}
10161016
case AsyncAuthType::AUTH_DIGEST:
10171017
{
1018-
size_t len = strlen(T_DIGEST_) + strlen(T_realm__) + strlen(T_auth_nonce) + 32 + strlen(T__opaque) + 32 + 1;
1018+
size_t len = sizeof(T_DIGEST_) - 1 + sizeof(T_realm__) - 1 + sizeof(T_auth_nonce) - 1 + 32 + sizeof(T__opaque) - 1 + 32 + 1;
10191019
String header;
10201020
if (header.reserve(len + strlen(realm))) {
10211021
const String nonce = genRandomMD5();

src/WebResponses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String &path, const char *con
756756
int filenameStart = path.lastIndexOf('/') + 1;
757757
const char *filename = path.c_str() + filenameStart;
758758
String buf;
759-
buf.reserve(strlen(T_attachment) + strlen(filename) + 2);
759+
buf.reserve(sizeof(T_attachment) - 1 + strlen(filename) + 2);
760760
buf = T_attachment;
761761
buf += filename;
762762
buf += "\"";
@@ -794,7 +794,7 @@ AsyncFileResponse::AsyncFileResponse(File content, const String &path, const cha
794794
int filenameStart = path.lastIndexOf('/') + 1;
795795
const char *filename = path.c_str() + filenameStart;
796796
String buf;
797-
buf.reserve(strlen(T_attachment) + strlen(filename) + 2);
797+
buf.reserve(sizeof(T_attachment) - 1 + strlen(filename) + 2);
798798
buf = T_attachment;
799799
buf += filename;
800800
buf += "\"";

0 commit comments

Comments
 (0)