pack/unpack better in (network-)short-non-16-bits and
[p5sagit/p5-mst-13.2.git] / pp.c
diff --git a/pp.c b/pp.c
index d5b7081..a9ced11 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3549,6 +3549,10 @@ PP(pp_unpack)
                 {
                    while (len-- > 0) {
                        COPY16(s, &ashort);
+#if SHORTSIZE > SIZE16
+                       if (ashort > 32767)
+                         ashort -= 65536;
+#endif
                        s += SIZE16;
                        culong += ashort;
                    }
@@ -3572,6 +3576,10 @@ PP(pp_unpack)
                 {
                    while (len-- > 0) {
                        COPY16(s, &ashort);
+#if SHORTSIZE > SIZE16
+                       if (ashort > 32767)
+                         ashort -= 65536;
+#endif
                        s += SIZE16;
                        sv = NEWSV(38, 0);
                        sv_setiv(sv, (IV)ashort);
@@ -3747,6 +3755,10 @@ PP(pp_unpack)
                 {
                    while (len-- > 0) {
                        COPY32(s, &along);
+#if LONGSIZE > SIZE32
+                       if (along > 2147483647)
+                         along -= 4294967296;
+#endif
                        s += SIZE32;
                        if (checksum > 32)
                            cdouble += (double)along;
@@ -3773,6 +3785,10 @@ PP(pp_unpack)
                 {
                    while (len-- > 0) {
                        COPY32(s, &along);
+#if LONGSIZE > SIZE32
+                       if (along > 2147483647)
+                         along -= 4294967296;
+#endif
                        s += SIZE32;
                        sv = NEWSV(42, 0);
                        sv_setiv(sv, (IV)along);
@@ -4555,7 +4571,7 @@ PP(pp_pack)
            }
            break;
        case 's':
-#if SHORTSIZE != 2
+#if SHORTSIZE != SIZE16
            if (natint) {
                while (len-- > 0) {
                    fromstr = NEXTFROM;