# [PATCH] exif warning fix?

- Thread: https://externals.io/message/15340
- Original archive: https://news-web.php.net/php.internals/15340
- Started by Joe Orton on 2005-03-10T10:17:12+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

---

## #15340 — Joe Orton — 2005-03-10T10:17:12+00:00

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

Testing "length >= LONG_MAX" where length is an int is always false, and
gcc gives a warning for it.  Perhaps something like this was intended?

Index: ext/exif/exif.c
===================================================================
RCS file: /repository/php-src/ext/exif/exif.c,v
retrieving revision 1.170
diff -u -r1.170 exif.c
--- ext/exif/exif.c	2 Mar 2005 18:21:45 -0000	1.170
+++ ext/exif/exif.c	10 Mar 2005 10:15:31 -0000
@@ -1557,7 +1557,7 @@
 	image_info_data  *info_data;
 	image_info_data  *list;
 
-	if (length >= LONG_MAX) {
+	if ((unsigned int)length >= INT_MAX) {
 		return;
 	}

---

## #15341 — Ard Biesheuvel — 2005-03-10T10:23:51+00:00

URL: https://externals.io/message/15340#15341 · In reply to: #15340

Joe Orton wrote:
> Testing "length >= LONG_MAX" where length is an int is always false, and
> gcc gives a warning for it.  Perhaps something like this was intended?
> 

On 64-bit it is always false, however on 32-bit 'length == LONG_MAX' can 
be true. That's probably why noone caught the warning so far, as gcc 
would not emit it on a 32-bit system.

If you're testing for overflow, casting to unsigned int won't help you 
here, as the overflow will already have occurred when length was 
assigned its value.

-- 
Ard



> Index: ext/exif/exif.c
> ===================================================================
> RCS file: /repository/php-src/ext/exif/exif.c,v
> retrieving revision 1.170
> diff -u -r1.170 exif.c
> --- ext/exif/exif.c	2 Mar 2005 18:21:45 -0000	1.170
> +++ ext/exif/exif.c	10 Mar 2005 10:15:31 -0000
> @@ -1557,7 +1557,7 @@
>  	image_info_data  *info_data;
>  	image_info_data  *list;
>  
> -	if (length >= LONG_MAX) {
> +	if ((unsigned int)length >= INT_MAX) {
>  		return;
>  	}

---

## #15342 — Joe Orton — 2005-03-10T10:43:55+00:00

URL: https://externals.io/message/15340#15342 · In reply to: #15341

> Joe Orton wrote:
> > […]
> 
> On 64-bit it is always false, however on 32-bit 'length == LONG_MAX' can 
> be true. That's probably why noone caught the warning so far, as gcc 
> would not emit it on a 32-bit system.
> 
> If you're testing for overflow, casting to unsigned int won't help you 
> here, as the overflow will already have occurred when length was 
> assigned its value.

Yes, sorry, I haven't turned my brain on yet this morning.  So perhaps a
test for (length < 0) is all that's really needed; I can't see why
length == INT_MAX is particularly a special case here...

joe
