Authentication-Results: mail-b.sr.ht; dkim=none Received: from mail.nullprogram.com (mail.nullprogram.com [192.241.191.137]) by mail-b.sr.ht (Postfix) with ESMTPS id 72AE811EEAC for <~skeeto/public-inbox@lists.sr.ht>; Wed, 5 Jan 2022 02:16:25 +0000 (UTC) Received: from nullprogram.com (localhost [127.0.0.1]) by mail.nullprogram.com (Postfix) with ESMTPS id 4A0A3C787A; Tue, 4 Jan 2022 21:16:24 -0500 (EST) Date: Tue, 4 Jan 2022 21:16:23 -0500 From: Christopher Wellons To: Eric Farmer Cc: ~skeeto/public-inbox@lists.sr.ht Subject: Re: A new protocol and tool for PNG file attachments Message-ID: <20220105021623.6wq5zlciqfgtdlrp@nullprogram.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Thanks, Eric! That very project being shared around was what got the gears turning for my project. I was inspired by the headline, skimmed the PNG specification to brush up on the format, went to sleep, and by morning I had a few ideas for how to tackle it. I Initially considered compatibility with pngsource (i.e. the draw.io format), but saw the XML and noped out. > what motivates the `void *` buffer type in `crc32_update` That's just the result of a copy-paste incompletely integrated into the new project. :-) https://github.com/skeeto/scratch/blob/master/checksums/crc32.h The original is C89 — no stdint.h, no for loop variable declaration — and, being agnostic of the surrounding context, accepts a generic block of memory, which as you pointed out could be a struct. I like to avoid even "char *" when accepting raw memory since it's opinionated about the sign of its input. As I worked, I massaged it into the context of pngattach, adapting it to C99 and fixed-width integers. Since I use "unsigned char" consistently throughout the rest of the program as an alias for raw PNG bytes, I probably should have changed that aspect of its interface as well. Side note: In the past when processing string data ("char *") as though unsigned bytes, such as to decode UTF-8 or do table lookups, I've cast "char *" to "unsigned char *". However, I now use "&0xff" on the read value to force it to the equivalent unsigned value without the awkward pointer cast. Every compiler I've tested handles this perfectly (turns it into a zero-extension), so there's no penalty. Technically this requires a two's complement representation, but practically speaking, none of my programs will ever see a computer that isn't so.