tool_operate: avoid strlen() -1 on zero length content from file

Follow-up to 65b563a96a

Closes #11959
This commit is contained in:
Daniel Stenberg 2023-09-27 10:27:07 +02:00
parent 93885cf3a8
commit c50cbac0f0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -749,14 +749,13 @@ static char *ipfs_gateway(void)
Curl_safefree(gateway_composed_file_path);
if(gateway_file) {
char *gateway_buffer = NULL;
char *buf = NULL;
if((PARAM_OK == file2string(&gateway_buffer, gateway_file)) &&
gateway_buffer) {
bool add_slash = (gateway_buffer[strlen(gateway_buffer) - 1] != '/');
gateway = aprintf("%s%s", gateway_buffer, (add_slash) ? "/" : "");
Curl_safefree(gateway_buffer);
if((PARAM_OK == file2string(&buf, gateway_file)) && buf && *buf) {
bool add_slash = (buf[strlen(buf) - 1] != '/');
gateway = aprintf("%s%s", buf, (add_slash) ? "/" : "");
}
Curl_safefree(buf);
if(gateway_file)
fclose(gateway_file);