From 0c575ccc740828d61dd42c5305e61c19e1f1d1df Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Sun, 3 Oct 2010 22:23:08 +0000 Subject: [PATCH] If a symbol is printed without a value list at the very end of a basic_io dump, we might access a non-existing character position. This has been fixed and the string length calculation is now only done once. --- src/IDF/Scm/Monotone/BasicIO.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/IDF/Scm/Monotone/BasicIO.php b/src/IDF/Scm/Monotone/BasicIO.php index 78707c5..9c8c286 100644 --- a/src/IDF/Scm/Monotone/BasicIO.php +++ b/src/IDF/Scm/Monotone/BasicIO.php @@ -38,14 +38,15 @@ class IDF_Scm_Monotone_BasicIO { $pos = 0; $stanzas = array(); + $length = strlen($in); - while ($pos < strlen($in)) { + while ($pos < $length) { $stanza = array(); - while ($pos < strlen($in)) { + while ($pos < $length) { if ($in[$pos] == "\n") break; $stanzaLine = array('key' => '', 'values' => array(), 'hash' => null); - while ($pos < strlen($in)) { + while ($pos < $length) { $ch = $in[$pos]; if ($ch == '"' || $ch == '[') break; ++$pos; @@ -53,6 +54,9 @@ class IDF_Scm_Monotone_BasicIO $stanzaLine['key'] .= $ch; } + // symbol w/o a value list + if ($pos >= $length || $in[$pos] == "\n") break; + if ($in[$pos] == '[') { unset($stanzaLine['values']); ++$pos; // opening square bracket @@ -67,7 +71,7 @@ class IDF_Scm_Monotone_BasicIO while ($in[$pos] == '"') { ++$pos; // opening quote $stanzaLine['values'][$valCount] = ''; - while ($pos < strlen($in)) { + while ($pos < $length) { $ch = $in[$pos]; $pr = $in[$pos-1]; if ($ch == '"' && $pr != '\\') break; ++$pos; @@ -75,7 +79,7 @@ class IDF_Scm_Monotone_BasicIO } ++$pos; // closing quote - if ($pos >= strlen($in)) + if ($pos >= $length) break; if ($in[$pos] == ' ') {