# [PATCH] Zend _CHECK_MEMORY_LIMIT fix

- Thread: https://externals.io/message/4812
- Original archive: https://news-web.php.net/php.internals/4812
- Started by Joe Orton on 2003-10-13T11:36:50+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4812 — Joe Orton — 2003-10-13T11:36:50+00:00

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

It looks like the _CHECK_MEMORY_LIMIT macro has one of the conditions
reversed: the diff below is rather unreadable, if you read the original
code the problem should be obvious:

  if (file)
    zend_error("..exhausted (tried...", ...)
  else
    zend_error("...exhausted at %s:%d (tried...", ..., file, lineno, ...)

gcc 3.3 with -Wall is giving warnings on this macro since it expands to
always pass a `NULL` as the %s argument in some places, but this isn't a
real issue when inside an if (NULL) condition.

Index: Zend/zend_alloc.c
===================================================================
RCS file: /repository/Zend/Attic/zend_alloc.c,v
retrieving revision 1.105.4.3
diff -u -r1.105.4.3 zend_alloc.c
--- Zend/zend_alloc.c	15 Apr 2003 01:30:46 -0000	1.105.4.3
+++ Zend/zend_alloc.c	13 Oct 2003 11:21:27 -0000
@@ -70,9 +70,9 @@
 									if (AG(memory_limit)+1048576 > AG(allocated_memory) - rs) { \
 										AG(memory_limit) = AG(allocated_memory) + 1048576; \
 										if (file) { \
-											zend_error(E_ERROR,"Allowed memory size of %d bytes exhausted (tried to allocate %d bytes)", php_mem_limit, s); \
-										} else { \
 											zend_error(E_ERROR,"Allowed memory size of %d bytes exhausted at %s:%d (tried to allocate %d bytes)", php_mem_limit, file, lineno, s); \
+										} else { \
+											zend_error(E_ERROR,"Allowed memory size of %d bytes exhausted (tried to allocate %d bytes)", php_mem_limit, s); \
 										} \
 									} else { \
 										if (file) { \
