Skip to content

Commit

Permalink
escape: replace Curl_isunreserved with ISUNRESERVED
Browse files Browse the repository at this point in the history
- Use the ALLCAPS version of the macro so that it is clear a macro is
  being called that evaluates the variable multiple times.

- Also capitalize macro isurlpuntcs => ISURLPUNTCS since it evaluates
  a variable multiple times.

This is a follow-up to 291d225 which changed Curl_isunreserved into an
alias macro for ISUNRESERVED. The problem is the former is not easily
identified as a macro by the caller, which could lead to a bug.

For example, ISUNRESERVED(*foo++) is easily identifiable as wrong but
Curl_isunreserved(*foo++) is not even though they both are the same.

Closes #11846
  • Loading branch information
jay committed Sep 14, 2023
1 parent 23c3f81 commit 7a2421d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/curl_ctype.h
Expand Up @@ -43,9 +43,9 @@
#define ISDIGIT(x) (((x) >= '0') && ((x) <= '9'))
#define ISBLANK(x) (((x) == ' ') || ((x) == '\t'))
#define ISSPACE(x) (ISBLANK(x) || (((x) >= 0xa) && ((x) <= 0x0d)))
#define isurlpuntcs(x) (((x) == '-') || ((x) == '.') || ((x) == '_') || \
#define ISURLPUNTCS(x) (((x) == '-') || ((x) == '.') || ((x) == '_') || \
((x) == '~'))
#define ISUNRESERVED(x) (ISALNUM(x) || isurlpuntcs(x))
#define ISUNRESERVED(x) (ISALNUM(x) || ISURLPUNTCS(x))


#endif /* HEADER_CURL_CTYPE_H */
2 changes: 1 addition & 1 deletion lib/escape.c
Expand Up @@ -72,7 +72,7 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
while(length--) {
unsigned char in = *string++; /* treat the characters unsigned */

if(Curl_isunreserved(in)) {
if(ISUNRESERVED(in)) {
/* append this */
if(Curl_dyn_addn(&d, &in, 1))
return NULL;
Expand Down
2 changes: 0 additions & 2 deletions lib/escape.h
Expand Up @@ -28,8 +28,6 @@

#include "curl_ctype.h"

#define Curl_isunreserved(x) ISUNRESERVED(x)

enum urlreject {
REJECT_NADA = 2,
REJECT_CTRL,
Expand Down
2 changes: 1 addition & 1 deletion lib/urlapi.c
Expand Up @@ -1865,7 +1865,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
if(result)
return CURLUE_OUT_OF_MEMORY;
}
else if(Curl_isunreserved(*i) ||
else if(ISUNRESERVED(*i) ||
((*i == '/') && urlskipslash) ||
((*i == '=') && equalsencode)) {
if((*i == '=') && equalsencode)
Expand Down

0 comments on commit 7a2421d

Please sign in to comment.