MESSAGE
DATE | 2016-12-06 |
FROM | John Bowler
|
SUBJECT | Re: [Learn] [png-mng-implement] 4 byte length storage
|
From learn-bounces-at-nylxs.com Tue Dec 6 14:22:19 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id A7FCD161316; Tue, 6 Dec 2016 14:22:19 -0500 (EST) X-Original-To: learn-at-www.mrbrklyn.com Delivered-To: learn-at-www.mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 1000) id 6F5CA161316; Tue, 6 Dec 2016 14:22:17 -0500 (EST) Resent-From: Ruben Safir Resent-Date: Tue, 6 Dec 2016 14:22:17 -0500 Resent-Message-ID: <20161206192217.GD29134-at-www.mrbrklyn.com> Resent-To: learn-at-mrbrklyn.com X-Original-To: ruben-at-mrbrklyn.com Delivered-To: ruben-at-mrbrklyn.com Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by mrbrklyn.com (Postfix) with ESMTP id CE660161312 for ; Tue, 6 Dec 2016 12:33:02 -0500 (EST) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cEJbi-0002En-Pv; Tue, 06 Dec 2016 17:32:46 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cEJbh-0002Ef-VX for png-mng-implement-at-lists.sourceforge.net; Tue, 06 Dec 2016 17:32:45 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.161.193 as permitted sender) client-ip=209.85.161.193; envelope-from=john.cunningham.bowler-at-gmail.com; helo=mail-yw0-f193.google.com; Received: from mail-yw0-f193.google.com ([209.85.161.193]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1cEJbh-0002iE-1T for png-mng-implement-at-lists.sourceforge.net; Tue, 06 Dec 2016 17:32:45 +0000 Received: by mail-yw0-f193.google.com with SMTP id a10so29423084ywa.1 for ; Tue, 06 Dec 2016 09:32:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=5E5edoLTYOtweNUWgJzghiQoxVQEoGC4LKkqTdrrLUU=; b=EkzSvwR1lR56PJG5eAJAInOmvsIjeMfTgQC3nowItfIFFHJIK0tjkV34I/G0Wh7t6v uXkFrgZspPNBrg6ePcepxlcQ1HmhpPIrAHWcSYw/B1KHv1zmKUcvxXbJBL0ZsX0OuVvW cY/B2Bl3RkAtuGM+hZw2X5ooWFW7TdLG4lpjeayc83KZ9t03d/bNRh5HvwKGzTC8k3qi b6Bq/gE+RigtgEotAP2V5G5JYwY3PqJRdW13pceJ/Fe6fF++CSpMawc7GbWemf5qd2ar 7ioVUAqQmpplnOIaVVpTxhUuE6/Zjtg4EXDgFOdq4aPI3ili+eW9UgHZvpCNJRLHUWtZ WmbQ== X-Gm-Message-State: AKaTC03GiWgdJipsLqsPgdCZqBOXDhls9YnowY5un39zwm9JcsOzKfngFjK2dQBPlDgZjGqjVqjU6n7qjtT5wg== X-Received: by 10.37.57.139 with SMTP id g133mr31347881yba.14.1481045559296; Tue, 06 Dec 2016 09:32:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.46.66 with HTTP; Tue, 6 Dec 2016 09:32:38 -0800 (PST) In-Reply-To: References: <17705460-c78b-6310-807f-417193dc4f6b-at-mrbrklyn.com> From: John Bowler Date: Tue, 6 Dec 2016 09:32:38 -0800 Message-ID: To: "PNG/MNG implementation discussion list" X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.161.193 listed in list.dnswl.org] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (john.cunningham.bowler[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1cEJbh-0002iE-1T X-BeenThere: png-mng-implement-at-lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Subject: Re: [Learn] [png-mng-implement] 4 byte length storage X-BeenThere: learn-at-nylxs.com Reply-To: PNG/MNG implementation discussion list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
On Tue, Dec 6, 2016 at 8:55 AM, Andreas Kleinert wrote: > I have not really checked your code in detail, but are you sure it is not just big vs. little endian conversion...?!
That's why '13' (0x0000000D) appears as 218103808 (0x0D000000), but there are other issues in the code that are perhaps best covered by an online tutorial such as this one:
https://isocpp.org/wiki/faq/serialization
(That's C++ specific).
One issue is that the code relies on uint32_t being a four byte quantity, CHUNK is a typedef of uint32_t:
char * cur = get_index(); CHUNK * tmp = reinterpret_cast(cur);
Certainly uint32_t is required to have exactly 32 bits and therefore behave as a 32-bit value for modular arithmetic (per the ANSI C spec), however I don't know that the representation is constrained to be 4 bytes. I would be surprised if C89 (which formalized the type) had done that and so far as I can see the above code has undefined behavior.
The general rule for serialization is to either use well-defined primitives or to do it yourself; the code is not exactly difficult to write, though it can be difficult to get right sometimes ;-)
John Bowler
------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today.http://sdm.link/xeonphi _______________________________________________ png-mng-implement mailing list png-mng-implement-at-lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/png-mng-implement _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|