prevent sign-extension in unpack when needed
authorceriel <none@none>
Tue, 19 Feb 1991 12:13:08 +0000 (12:13 +0000)
committerceriel <none@none>
Tue, 19 Feb 1991 12:13:08 +0000 (12:13 +0000)
lang/pc/libpc/pac.c
lang/pc/libpc/unp.c

index c40e6fe..6ce3751 100644 (file)
@@ -47,6 +47,14 @@ _pac(ad,zd,zp,i,ap) int i; struct descr *ad,*zd; char *zp,*ap; {
                assert(ad->size == EM_WSIZE);
                while (--i >= 0)
                        *zp++ = *aptmp++;
+#if EM_WSIZE > 2
+       } else if (zd->size == 2) {
+               int *aptmp = (int *)ap;
+               short *zptmp = (short *) zp;
+               assert(ad->size == EM_WSIZE);
+               while (--i >= 0)
+                       *zptmp++ = *aptmp++;
+#endif
        } else {
                assert(ad->size == zd->size);
                while (--i >= 0)
index d1c35ca..d9d5a5f 100644 (file)
@@ -34,7 +34,7 @@ struct descr {
        int     size;
 };
 
-_unp(ad,zd,i,ap,zp) int i; struct descr *ad,*zd; char *ap,*zp; {
+_unp(ad,zd,i,ap,zp,noext) int i; struct descr *ad,*zd; char *ap,*zp; int noext; {
 
        if (zd->diff > ad->diff ||
                        (i -= ad->low) < 0 ||
@@ -46,7 +46,17 @@ _unp(ad,zd,i,ap,zp) int i; struct descr *ad,*zd; char *ap,*zp; {
                int *aptmp = (int *) ap;
                assert(ad->size == EM_WSIZE);
                while (--i >= 0)
-                       *aptmp++ = *zp++;
+                       if (noext) *aptmp++ = *zp++ & 0377;
+                       else *aptmp++ = *zp++;
+#if EM_WSIZE > 2
+       } else if (zd->size == 2) {
+               int *aptmp = (int *) ap;
+               short *zptmp = (short *) zp;
+               assert(ad->size == EM_WSIZE);
+               while (--i >= 0)
+                       if (noext) *aptmp++ = *zptmp++ & 0177777;
+                       else *aptmp++ = *zptmp++;
+#endif
        } else {
                assert(ad->size == zd->size);
                while (--i >= 0)