curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] curl: Fix compile warning on Fedora-14.

From: John Marshall <John.W.Marshall_at_glasgow.ac.uk>
Date: Mon, 11 Sep 2017 15:58:50 +0000

On 11 Sep 2017, at 11:40, Kamil Dudka via curl-library <curl-library_at_cool.haxx.se> wrote:
> While I respect your opinion, I disagree on this. Not using ternary operator
> leads to code duplication, which some programmers, including me, try to avoid.

Agreed, the now-duplicated assignment is less clear to me -- I have to stop and check whether the LHSes are the same. To micro-bikeshed this further, perhaps the following version avoids Ben's warning while being arguably simpler than the original (as it shows the possible code path combinations directly):

diff --git a/lib/mime.c b/lib/mime.c
index 74b653649..b26f914d5 100644
--- a/lib/mime.c
+++ b/lib/mime.c
@@ -296,9 +296,12 @@ static char *escape_string(const char *src, size_t len)
   for(i = 0; len; len--) {
     char c = *src++;
 
- if(c == '"' || c == '\\' || !c)
- dst[i++] = '\\';
- dst[i++] = c? c: '0';
+ if(c == '"' || c == '\\')
+ dst[i++] = '\\', dst[i++] = c;
+ else if(c == '\0')
+ dst[i++] = '\\', dst[i++] = '0';
+ else
+ dst[i++] = c;
   }
 
   dst[i] = '\0';

Adjust the comma operators to { ; } instead as taste dictates...

    John
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-09-11