Don't initialize end in pp_reverse when begin is NULL
Vincent Pit [Wed, 31 Mar 2010 12:33:32 +0000 (14:33 +0200)]
This change is a complement to 572558b47236782e60e41bd235c96eae7cbca3db.

Arithmetic on null pointers isn't defined by the C standard, so it may crash even before entering the loop.

pp.c

diff --git a/pp.c b/pp.c
index daa63af..e4660b3 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -5418,12 +5418,15 @@ PP(pp_reverse)
            }
            else {
                SV **begin = AvARRAY(av);
-               SV **end   = begin + AvFILLp(av);
 
-               while (begin && begin < end) {
-                   register SV * const tmp = *begin;
-                   *begin++ = *end;
-                   *end--   = tmp;
+               if (begin) {
+                   SV **end   = begin + AvFILLp(av);
+
+                   while (begin < end) {
+                       register SV * const tmp = *begin;
+                       *begin++ = *end;
+                       *end--   = tmp;
+                   }
                }
            }
        }