From 371abbde2e1e2ccd86bbb6bccd527afdfa13ed37 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 26 May 2017 14:51:48 +1000 Subject: [PATCH] Add comments about the minimum __WORDSIZE. --- cmd/internal/cgen/data.go | 2 +- cmd/internal/cgen/preamble.h | 4 ++++ gen/c/gif.c | 4 ++++ gen/h/gif.h | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/internal/cgen/data.go b/cmd/internal/cgen/data.go index cf60adc9..836d27b9 100644 --- a/cmd/internal/cgen/data.go +++ b/cmd/internal/cgen/data.go @@ -6,5 +6,5 @@ package cgen const preamble = "" + - "// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include \n#include \n\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#endif\n" + + "// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include \n#include \n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#endif\n" + "" diff --git a/cmd/internal/cgen/preamble.h b/cmd/internal/cgen/preamble.h index e1654651..04c2cad4 100644 --- a/cmd/internal/cgen/preamble.h +++ b/cmd/internal/cgen/preamble.h @@ -6,6 +6,10 @@ #include #include +// Puffs requires a word size of at least 32 bits because it assumes that +// converting a u32 to usize will never overflow. For example, the size of a +// decoded image is often represented, explicitly or implicitly in an image +// file, as a u32, and it is convenient to compare that to a buffer size. #if __WORDSIZE < 32 #error "Puffs requires a word size of at least 32 bits" #endif diff --git a/gen/c/gif.c b/gen/c/gif.c index 11e2c0e1..5c81ce6c 100644 --- a/gen/c/gif.c +++ b/gen/c/gif.c @@ -6,6 +6,10 @@ #include #include +// Puffs requires a word size of at least 32 bits because it assumes that +// converting a u32 to usize will never overflow. For example, the size of a +// decoded image is often represented, explicitly or implicitly in an image +// file, as a u32, and it is convenient to compare that to a buffer size. #if __WORDSIZE < 32 #error "Puffs requires a word size of at least 32 bits" #endif diff --git a/gen/h/gif.h b/gen/h/gif.h index b3f78007..f58d1f53 100644 --- a/gen/h/gif.h +++ b/gen/h/gif.h @@ -6,6 +6,10 @@ #include #include +// Puffs requires a word size of at least 32 bits because it assumes that +// converting a u32 to usize will never overflow. For example, the size of a +// decoded image is often represented, explicitly or implicitly in an image +// file, as a u32, and it is convenient to compare that to a buffer size. #if __WORDSIZE < 32 #error "Puffs requires a word size of at least 32 bits" #endif