Index: trunk/src/sh_static.c
===================================================================
--- trunk/src/sh_static.c	(revision 498)
+++ trunk/src/sh_static.c	(revision 501)
@@ -999,5 +999,5 @@
 		return -1;
 
-	while ((l = data[offset])) {
+	do {
 
 	        if (offset < INT_MAX)
@@ -1005,4 +1005,6 @@
 		else
 		        return -1;
+
+		l = data[offset];
 
 		if ((l & 0xc0) == (0xc0)) {
@@ -1018,5 +1020,6 @@
 		else
 		  return -1;
-	}
+
+	} while (l);
 
 	return offset - orig_offset;
@@ -1052,9 +1055,9 @@
 	        if (offset < INT_MAX) offset++;
 		else return -1;
-		if (measure && (total < INT_MAX))
-		    total++;
+		if (measure)
+		    { if (total < INT_MAX) total++; else return -1; }
 		if ((l & 0xc0) == (0xc0)) {
-		        if (measure && (total < INT_MAX))
-				total++;
+		        if (measure)
+			  { if (total < INT_MAX) total++; else return -1; }
 		        /* compressed item, redirect */ 
 			offset = ((l & 0x3f) << 8) | data[offset];
@@ -1082,6 +1085,6 @@
 		else
 		  return -1;
-		if (measure && (total <= (INT_MAX - l)))
-			total += l;
+		if (measure)
+		  { if (total <= (INT_MAX -l)) total += l; else return -1; }
 
 		if (used == INT_MAX)
@@ -1094,6 +1097,6 @@
 
 	/* The null byte must be counted too */
-	if (measure && (total < INT_MAX)) {
-	    total++;
+	if (measure) {
+	    if (total < INT_MAX) total++; else return -1; 
 	}
 
