commit 1a69f47149d069693500a0b99c5022959fc5e506 from: Omar Polo date: Sat Jan 13 13:12:51 2024 UTC iri_setquery: avoid needless else block commit - cd1d043db84e31534151a1db0dd47b5a1f201b5e commit + 1a69f47149d069693500a0b99c5022959fc5e506 blob - f43eb0605a26c289f40e9b4f0aced51aabb16e13 blob + 5dd1d612d44d6e1c0a3231ca8610e59090ade425 --- iri.c +++ iri.c @@ -720,20 +720,21 @@ iri_setquery(struct iri *iri, const char *p) buf = q = iri->iri_query; bufsize = sizeof(iri->iri_query); while (*p && (q - buf < bufsize)) { - if (unreserved(*p) || sub_delims(*p) || *p == ':' || *p == '@' || - *p == '/' || *p == '?') - *q++ = *p++; - else { - if (q - buf >= bufsize - 3) - goto err; - r = snprintf(tmp, sizeof(tmp), "%%%02X", (int)*p); - if (r < 0 || (size_t)r > sizeof(tmp)) - return (-1); - *q++ = tmp[0]; - *q++ = tmp[1]; - *q++ = tmp[2]; - p++; + if (unreserved(*p) || sub_delims(*p) || *p == ':' || + *p == '@' || *p == '/' || *p == '?') { + *q++ = *p++; + continue; } + + if (q - buf >= bufsize - 3) + goto err; + r = snprintf(tmp, sizeof(tmp), "%%%02X", (int)*p); + if (r < 0 || (size_t)r > sizeof(tmp)) + return (-1); + *q++ = tmp[0]; + *q++ = tmp[1]; + *q++ = tmp[2]; + p++; } if ((*p == '\0') && (q - buf < bufsize)) { iri->iri_flags |= IH_QUERY;