# patch: remove unneeded strlen() check from php_addcslashes

- Thread: https://externals.io/message/26923
- Original archive: https://news-web.php.net/php.internals/26923
- Started by Ron Korving on 2006-12-12T19:31:28+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26923 — Ron Korving — 2006-12-12T19:31:28+00:00

URL: https://externals.io/message/26923#26923

Hi,

The `strlen()` check on line 4730 of ext/standard/string.c is pointless
because of the length assignment in line 4720. Below is a patch (against
latest 5.2) to remove them.

Regards,

Ron Korving



Index: ext/standard/string.c
===================================================================
RCS file: /repository/php-src/ext/standard/string.c,v
retrieving revision 1.621
diff -u -r1.621 string.c
--- ext/standard/string.c 12 Dec 2006 18:17:56 -0000 1.621
+++ ext/standard/string.c 12 Dec 2006 19:26:40 -0000
@@ -4727,10 +4727,6 @@
   wlength = strlen(what);
  }

- if (!length) {
-  length = strlen(str);
- }
-
  php_charmask((unsigned char*)what, wlength, flags TSRMLS_CC);

  for (source = str, end = source + length, target = new_str; (c = *source)
|| (source < end); source++) {

---

## #26932 — Ilia Alshanetsky — 2006-12-13T15:36:36+00:00

URL: https://externals.io/message/26923#26932 · In reply to: #26923

This code is a fallback in instances where length is not know, which  
is something that may happen. Given that this is an API function I  
don't think we can make this change as it may break out-of-php code  
that relies on this functionality. I really don't think you'll see  
any visible gain by eliminating a if (!length) {} check.




> Hi,
>
> The `strlen()` check on line 4730 of ext/standard/string.c is pointless
> because of the length assignment in line 4720. Below is a patch  
> (against
> latest 5.2) to remove them.
>
> Regards,
>
> Ron Korving
>
>
>
> Index: ext/standard/string.c
> ===================================================================
> RCS file: /repository/php-src/ext/standard/string.c,v
> retrieving revision 1.621
> diff -u -r1.621 string.c
> --- ext/standard/string.c 12 Dec 2006 18:17:56 -0000 1.621
> +++ ext/standard/string.c 12 Dec 2006 19:26:40 -0000
> @@ -4727,10 +4727,6 @@
>    wlength = strlen(what);
>   }
>
> - if (!length) {
> -  length = strlen(str);
> - }
> -
>   php_charmask((unsigned char*)what, wlength, flags TSRMLS_CC);
>
>   for (source = str, end = source + length, target = new_str; (c =  
> *source)
> || (source < end); source++) {
>
> -- 
> 
> 
>
>

Ilia Alshanetsky

---

## #26933 — Ilia Alshanetsky — 2006-12-13T15:39:46+00:00

URL: https://externals.io/message/26923#26933 · In reply to: #26923

Nevermind the previous e-mail, I see that `strlen()` is already done  
inside safe_emalloc(), patch was applied, thanks.

Ilia
