Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101730 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5348 invoked from network); 30 Jan 2018 11:56:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2018 11:56:33 -0000 Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wm0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:35256] helo=mail-wm0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/21-24062-E6D507A5 for ; Tue, 30 Jan 2018 06:56:31 -0500 Received: by mail-wm0-f48.google.com with SMTP id r78so611623wme.0 for ; Tue, 30 Jan 2018 03:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=7YTYHFLvaaCcZk7KvB9Kk+DhgDZ/3nyfIClu7+gA5a4=; b=a7KUUj3VcmQD/ZztQpaimpuQGubj4/anlUBMzN+hEckBCpqxvJbbXRMZyvrEeO7jzy Y4NEflavKeFZwtXwaQImC95gRJl6b3yqSvRxqX4B4S6L6OSsKGf/QjYp6av9S4qwX0dZ 1/5TH7XgF2xeD/RTwKwiHuFS6n75XcK/iNFz2aGXvbgaJNHoZtdCdLtsQasAGBz+Lsh9 acxswiWrTzxJbqNLs4wTECjz7axuYELzr/LGHVsLJ+jzq0Bkthza2BPmnxlmFi+Dzhzh ip4EhuxhgtB5DckilrJbGZHmKfZ5qb14LfhG3mHJgIO9KL5pnY1CMrGoeJbiW11V4kws B+RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=7YTYHFLvaaCcZk7KvB9Kk+DhgDZ/3nyfIClu7+gA5a4=; b=MtLayyYdV+SM08tcqSbJkyszJVr2r4n3Swo5JLjCKbJU6qce95onMU5aOWN5YDoUkT tB6r/ylw+tgsTHhR7rhtZw1gl4lkkO53CQ7fKwkEAiM/rmGYTY5C65+R3XIenUL2+JOp ZTmjtGMZTxULZ0PCBq3eLYJ/+RQB4xk2KwpyZcVUsMfBPS4lJp8oTV9VAdbIcPhcJivh wBTV50DJf91OMVpF7WxqljgsWXWzoxx+SdDmlY5Ny/2lOp2NPzu4Cm6MD5KEruAXBaQ1 9jMcYZv8gVIfGptCr2a+upGpOu7MsjjNUf/TqAROTRO3a8imvLXOZlMUGpXA7KmXEMND MMrg== X-Gm-Message-State: AKwxytdmjv4mg0CmBNvlwkFO5U3xDxUv1Cv98RVAHAv29R50VIQqaF+G p42/PXL8mz07Lp8XRoz1ff4X1gC8y+mZ32/i5bAfgw== X-Google-Smtp-Source: AH8x224AvoolJvz3ai+21s2ZmCGiYw6YA0QHotT3REl4Bu5uux9qzjQQ4XTGO1S722ed4XcS3qJHP6kqg2gixWDe5N8= X-Received: by 10.80.137.178 with SMTP id g47mr51577811edg.100.1517313387759; Tue, 30 Jan 2018 03:56:27 -0800 (PST) MIME-Version: 1.0 Sender: are.you.winning@gmail.com Received: by 10.80.164.198 with HTTP; Tue, 30 Jan 2018 03:56:27 -0800 (PST) In-Reply-To: References: Date: Tue, 30 Jan 2018 11:56:27 +0000 X-Google-Sender-Auth: _LF8KWM8P3Ng78PW9bxXCjsefC4 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="f403045c29fe7d8ce10563fd0da8" Subject: Re: unpack() offset and consumed data measurement From: cw@daverandom.com (Chris Wright) --f403045c29fe7d8ce10563fd0da8 Content-Type: text/plain; charset="UTF-8" On 28 January 2018 at 12:12, Chris Wright wrote: > > Here is some code that demonstrates the problem: > > /* This is the only way to know for certain how big float is on the > local system */ > define('FLOAT_WIDTH', strlen(pack('f', 0.0))); > > /* an exaggerated example using two variable width codes and a code > that > does not produce output but modifies the input buffer offset */ > $pieces = unpack('f/X/Z*', $data, $offset); > > /* we now have to modify the offset before we can continue to unpack > data */ > $offset += FLOAT_WIDTH // f > - 1 // x > + strlen($pieces[3]); // Z* > Re-reading this mail I have noticed there was a small mistake in the code sample, in that I forgot to include the terminating null byte for the Z* data. This (unintentionally) demonstrates the exact reason I would like to add this, as it's very easy to accidentally write subtle bugs. --f403045c29fe7d8ce10563fd0da8--