From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9068C1FAF6 for ; Thu, 15 Dec 2022 20:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1671137577; bh=puLNzqkv7zotEWexqXabOwt3IFRNUPHTWn0TGkGjc6k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=zioIXEIvXfOlbMbZSjHVTcsUZTipAzlDH/BwVVHlLiWOVnF596BoKFWFPB/ulLzx6 WywE/1nDGZ+GgmWFJ6KDx/VaUUahHjnRilULMy3yevJb/IYauiPcBc9h+QG5gvtIqi kg4qtP/SNVj+IwQLWSCdDrXkdBJ07YeX2W8EpXFk= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 08/19] httpd: drop unnecessary AND ops from base-64 Date: Thu, 15 Dec 2022 20:52:44 +0000 Message-Id: <20221215205255.27840-9-e@80x24.org> In-Reply-To: <20221215205255.27840-1-e@80x24.org> References: <20221215205255.27840-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We only use unsigned chars, so we can let truncation do its thing and not overflow. --- mwrap_httpd.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mwrap_httpd.h b/mwrap_httpd.h index e5790aa..606ae20 100644 --- a/mwrap_httpd.h +++ b/mwrap_httpd.h @@ -361,7 +361,7 @@ static void write_b64_url(FILE *fp, const uint8_t *in, size_t len) "abcdefghijklmnopqrstuvwxyz" "0123456789-_"; uint8_t o[4]; while (len > 3) { - o[0] = b64[(in[0] >> 2) & 0x3f]; + o[0] = b64[in[0] >> 2]; o[1] = b64[((in[0] << 4) | (in[1] >> 4)) & 0x3f]; o[2] = b64[((in[1] << 2) | (in[2] >> 6)) & 0x3f]; o[3] = b64[in[2] & 0x3f]; @@ -372,7 +372,7 @@ static void write_b64_url(FILE *fp, const uint8_t *in, size_t len) if (len) { size_t i = 2; - o[0] = b64[(in[0] >> 2) & 0x3f]; + o[0] = b64[in[0] >> 2]; o[1] = b64[((in[0] << 4) | (--len ? (in[1] >> 4) : 0)) & 0x3f]; if (len) o[i++] = b64[((in[1] << 2) | @@ -410,11 +410,11 @@ static bool b64_url_decode(const void *ptr, size_t *len) case 0: u = c << 2; break; case 1: *out++ = u | c >> 4; - u = (c & 0xf) << 4; + u = c << 4; break; case 2: *out++ = u | c >> 2; - u = (c & 0x3) << 6; + u = c << 6; break; case 3: *out++ = u | c; }