[git commit] get_header_tar: shrink 6->64 sign extension code

Denys Vlasenko vda.linux at googlemail.com
Wed Oct 19 12:51:12 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=f74f280a14f9b79a25e2ba29bab7a3056c94e647
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
getOctal                                             125     107     -18

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 archival/libarchive/get_header_tar.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 41e3efb..a63c0fb 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -79,10 +79,10 @@ static unsigned long long getOctal(char *str, int len)
 		 *
 		 * NB: tarballs with NEGATIVE unix times encoded that way were seen!
 		 */
-		v = first;
-		/* Sign-extend using 6th bit: */
-		v <<= sizeof(unsigned long long)*8 - 7;
-		v = (long long)v >> (sizeof(unsigned long long)*8 - 7);
+		/* Sign-extend 7bit 'first' to 64bit 'v' (that is, using 6th bit as sign): */
+		first <<= 1;
+		first >>= 1; /* now 7th bit = 6th bit */
+		v = first;   /* sign-extend 8 bits to 64 */
 		while (--len != 0)
 			v = (v << 8) + (unsigned char) *str++;
 	}


More information about the busybox-cvs mailing list