This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 4e5922461f14819e66ba93de4097db1fd5343c4c (commit) via e721ab54137f3fd2507cca0c6263181b7738a245 (commit) via f8f2f1760b2b9cbfb7d1f08c8ef21c7e1520fd34 (commit) via 2cbd315068e8420d15539d287deaa9342129d1b2 (commit) via 75abfe3dd34074497567b4c373ab968a8c1a70c2 (commit) from 9616b4dac5b3d857003e4be82328b689b4d5194d (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/4e5922461f14819e66ba93de4097db1fd5343...
commit 4e5922461f14819e66ba93de4097db1fd5343c4c Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 8 15:10:46 2013 +0200
core: ContextAlloc: Add check for zero width/height + test.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index ff65884..6279890 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -50,6 +50,12 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) GP_DEBUG(1, "Allocating context %u x %u - %s", w, h, GP_PixelTypeName(type));
+ if (w <= 0 || h <= 0) { + GP_WARN("Trying to allocate context with zero width and/or height"); + errno = EINVAL; + return NULL; + } + pixels = malloc(bpr * h); context = malloc(sizeof(GP_Context));
diff --git a/tests/core/Context.c b/tests/core/Context.c index af26656..fbabf17 100644 --- a/tests/core/Context.c +++ b/tests/core/Context.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -25,6 +25,7 @@ Very basic GP_Context tests.
*/ +#include <errno.h>
#include <core/GP_Context.h>
@@ -204,6 +205,43 @@ static int SubContext_Create(void) return TST_SUCCESS; }
+static int context_zero_w(void) +{ + GP_Context *c; + + c = GP_ContextAlloc(0, 200, GP_PIXEL_G8); + + if (c != NULL) { + tst_msg("Context with zero width successfuly allocated"); + return TST_FAILED; + } + + if (errno != EINVAL) { + tst_msg("Expected errno set to EINVAL"); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +static int context_zero_h(void) +{ + GP_Context *c; + + c = GP_ContextAlloc(200, 0, GP_PIXEL_G8); + + if (c != NULL) { + tst_msg("Context with zero height successfuly allocated"); + return TST_FAILED; + } + + if (errno != EINVAL) { + tst_msg("Expected errno set to EINVAL"); + return TST_FAILED; + } + + return TST_SUCCESS; +}
const struct tst_suite tst_suite = { .suite_name = "Context Testsuite", @@ -215,6 +253,10 @@ const struct tst_suite tst_suite = { .flags = TST_CHECK_MALLOC}, {.name = "SubContext Create", .tst_fn = SubContext_Create}, + {.name = "Context Create w = 0", + .tst_fn = context_zero_w}, + {.name = "Context Create h = 0", + .tst_fn = context_zero_h}, {.name = NULL}, } };
http://repo.or.cz/w/gfxprim.git/commit/e721ab54137f3fd2507cca0c6263181b7738a...
commit e721ab54137f3fd2507cca0c6263181b7738a245 Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 8 14:59:04 2013 +0200
loaders: BMP: Add check for non-zero width and height.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index d2c7683..cb7a61b 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -575,6 +575,12 @@ GP_Context *GP_ReadBMP(FILE *f, GP_ProgressCallback *callback) if ((err = read_bitmap_header(f, &header))) goto err1;
+ if (header.w <= 0 || header.h == 0) { + GP_WARN("Width and/or Height is not > 0"); + err = EIO; + goto err1; + } + if (header.compress_type != COMPRESS_RGB) { GP_DEBUG(2, "Unknown compression type"); err = ENOSYS;
http://repo.or.cz/w/gfxprim.git/commit/f8f2f1760b2b9cbfb7d1f08c8ef21c7e1520f...
commit f8f2f1760b2b9cbfb7d1f08c8ef21c7e1520fd34 Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 8 14:52:49 2013 +0200
loaders: BMP: Adapt to the ByteUtils.
* Fix existing usage
* Make use in header loader
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c index 8254bac..d2c7683 100644 --- a/libs/loaders/GP_BMP.c +++ b/libs/loaders/GP_BMP.c @@ -150,21 +150,16 @@ static uint32_t get_palette_size(struct bitmap_info_header *header)
static int read_bitmap_info_header(FILE *f, struct bitmap_info_header *header) { - uint8_t buf[36]; + uint16_t nr_planes;
- if (fread(buf, 1, sizeof(buf), f) != sizeof(buf)) { + if (GP_FRead(f, "L4 L4 L2 L2 L4 I12 L4 I4", + &header->w, &header->h, &nr_planes, &header->bpp, + &header->compress_type, &header->palette_colors) != 8) { + GP_DEBUG(1, "Failed to read bitmap info header"); return EIO; }
- header->w = BUF_TO_4(buf, 0); - header->h = BUF_TO_4(buf, 4); - header->bpp = BUF_TO_2(buf, 10); - header->compress_type = BUF_TO_4(buf, 12); - header->palette_colors = BUF_TO_4(buf, 28); - - uint16_t nr_planes = BUF_TO_2(buf, 8); - /* This must be 1 according to specs */ if (nr_planes != 1) GP_DEBUG(1, "Number of planes is %"PRId16" should be 1", @@ -648,12 +643,12 @@ static int bmp_write_header(struct bitmap_info_header *header, FILE *f) uint32_t file_size = bitmap_size + header->header_size + 14;
/* Bitmap Header */ - if (GP_FWrite(f, "%a2%l4%x00%x00%x00%x00%l4", "BM", + if (GP_FWrite(f, "A2 L4 0x00 0x00 0x00 0x00 L4", "BM", file_size, header->pixel_offset) != 7) return EIO; /* Bitmap Info Header */ - if (GP_FWrite(f, "%l4%l4%l4%l2%l2%l4%l4%l4%l4%l4%l4", + if (GP_FWrite(f, "L4 L4 L4 L2 L2 L4 L4 L4 L4 L4 L4", header->header_size, header->w, header->h, 1, header->bpp, header->compress_type, bitmap_size, 0, 0, header->palette_colors, 0) != 11)
http://repo.or.cz/w/gfxprim.git/commit/2cbd315068e8420d15539d287deaa9342129d...
commit 2cbd315068e8420d15539d287deaa9342129d1b2 Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 8 14:30:49 2013 +0200
loaders: Change ByteUtils format string.
Making the format string more readable.
Also fix a few bugs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/byte_utils.c b/demos/c_simple/byte_utils.c index 0b122f0..4c9053f 100644 --- a/demos/c_simple/byte_utils.c +++ b/demos/c_simple/byte_utils.c @@ -50,7 +50,7 @@ static void write_file(void) uint8_t bpp = 4; char *sig = "MG";
- ret = GP_FWrite(f, "%a2%x00%x00%b2%b2%b1", sig, w, h, bpp); + ret = GP_FWrite(f, "A2 0x00 0x00 B2 B2 B1", sig, w, h, bpp);
if (ret != 6) printf("Failed to write header, ret = %in", ret); @@ -75,9 +75,9 @@ static void read_file(void) uint8_t bpp; char sig[3] = {0};
- ret = GP_FRead(f, "%a2%x00%x00%b2%b2%b1", sig, &w, &h, &bpp); + ret = GP_FRead(f, "A2 I2 B2 B2 B1", sig, &w, &h, &bpp);
- if (ret != 6) + if (ret != 5) printf("Failed to read header, ret = %in", ret);
printf("SIG=%s, w=%u, h=%u, bpp=%un", sig, w, h, bpp); diff --git a/include/loaders/GP_ByteUtils.h b/include/loaders/GP_ByteUtils.h index 0ec4732..cfa4bea 100644 --- a/include/loaders/GP_ByteUtils.h +++ b/include/loaders/GP_ByteUtils.h @@ -34,10 +34,14 @@ /* * The format string examples: * - * %l1 or %b1 assigns one byte - * %l2 assign two bytes in little endian - * %b4 assign four bytes in big endian - * %a6 read six bytes into array + * Type Modifiers: + * + * L - little endian (passed as value to write, passed as pointer to read) + * B - big endian + * A - byte array (passed as bointer for both read and write) + * I - ignore xxx bytes, GP_Fread() only + * + * Size Modifiers are just numbers. * * To read and write header with two byte signature, two reserved zero bytes * and size in 16 bit unsigned little endian variables. @@ -46,10 +50,10 @@ * uint16_t h; * char sig[2]; * - * if (GP_FWrite(f, "%a2%x00%x00%l2%l2", "SG", w, h) != 5) + * if (GP_FWrite(f, "A2 0x00 0x00 L2 L2", "SG", w, h) != 5) * //ERROR * - * if (GP_FRead(f, "%a2%x00%x00%l2%l2", sig, &w, &h) != 5) + * if (GP_FRead(f, "A2 I2 L2 L2", sig, &w, &h) != 4) * //ERROR */
diff --git a/libs/loaders/GP_ByteUtils.c b/libs/loaders/GP_ByteUtils.c index 9c88319..32abdd1 100644 --- a/libs/loaders/GP_ByteUtils.c +++ b/libs/loaders/GP_ByteUtils.c @@ -45,7 +45,7 @@ static int ctoi(char c, int *i) { switch (c) { case '0' ... '9': - *i += c - '0'; + *i = c - '0'; break; default: return 1; @@ -83,31 +83,37 @@ static const char *get_hex(const char *fmt, int *type, int *val)
*val = 0;
- if (ctoh(fmt[0], val)) + if (fmt[0] != 'x') { + GP_BUG("Expected x after 0 in hex constant"); + return NULL; + } + + if (ctoh(fmt[1], val)) return NULL;
(*val)<<=4;
- if (ctoh(fmt[1], val)) + if (ctoh(fmt[2], val)) return NULL;
- return fmt + 2; + return fmt + 3; }
static const char *get_int(const char *fmt, int *val) { - int i = 0; + int i = 0, add = 0;
*val = 0;
if (ctoi(fmt[i++], val)) return fmt; - - while (!ctoi(fmt[i], val)) { + + while (!ctoi(fmt[i], &add)) { *val *= 10; + *val += add; i++; } - + return fmt + i; }
@@ -126,10 +132,8 @@ static const char *get_array(const char *fmt, int *type, int *val)
static const char *get_lb_size(const char *fmt, int *val) { - *val = 0; - if (ctoi(fmt[0], val)) { - GP_WARN("Expected number after %%l or %%b, got '%c'", fmt[0]); + GP_WARN("Expected number got '%c'", fmt[0]); return NULL; }
@@ -146,38 +150,33 @@ static const char *get_lb_size(const char *fmt, int *val)
static const char *get_next(const char *fmt, int *type, int *val) { - if (fmt[0] == '0') - return NULL; - - if (fmt[0] != '%') { - GP_BUG("Unexpected character in format string '%c'", fmt[0]); - return NULL; - } - - switch (fmt[1]) { - /* byte array */ - case 'a': - return get_array(fmt + 2, type, val); + /* Eat spaces */ + while (fmt[0] == ' ') + fmt++; + + switch (fmt[0]) { + /* Byte array */ + case 'A': + return get_array(fmt + 1, type, val); break; - /* hexadecimal constant */ - case 'x': - return get_hex(fmt + 2, type, val); + /* Hexadecimal constant */ + case '0': + return get_hex(fmt + 1, type, val); break; /* 1, 2, 4 bytes long variable in defined endianity */ - case 'l': + case 'L': *type = LITTLE_ENDIAN_VAR; - return get_lb_size(fmt + 2, val); + return get_lb_size(fmt + 1, val); break; - case 'b': + case 'B': *type = BIG_ENDIAN_VAR; - return get_lb_size(fmt + 2, val); + return get_lb_size(fmt + 1, val); break; - case 'i': + case 'I': *type = IGNORE; - return get_int(fmt + 2, val); + return get_int(fmt + 1, val); break; case '0': - GP_BUG("Unexpecned end of format string"); return NULL; break; }
http://repo.or.cz/w/gfxprim.git/commit/75abfe3dd34074497567b4c373ab968a8c1a7...
commit 75abfe3dd34074497567b4c373ab968a8c1a70c2 Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 8 14:02:21 2013 +0200
loaders: Finish ByteUtils.
Add code to handle the endianity, needs to be tested.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_ByteUtils.c b/libs/loaders/GP_ByteUtils.c index e1c6ac0..9c88319 100644 --- a/libs/loaders/GP_ByteUtils.c +++ b/libs/loaders/GP_ByteUtils.c @@ -22,7 +22,14 @@
#include <stdarg.h>
+#ifdef __linux__ +#include <endian.h> +#else /* BSD Family */ +#include <machine/endian.h> +#endif + #include "core/GP_Debug.h" +#include "core/GP_Common.h"
#include "loaders/GP_ByteUtils.h"
@@ -60,10 +67,10 @@ static int ctoh(char c, int *i) *i += c - 'A' + 10; break; case '0': - GP_WARN("Unexpected end of the format string"); + GP_BUG("Unexpected end of the format string"); return 1; default: - GP_WARN("Expected [0-9]|[a-f][A-F] in hex constant, got '%c'", c); + GP_BUG("Expected [0-9]|[a-f][A-F] in hex constant, got '%c'", c); return 1; }
@@ -133,7 +140,7 @@ static const char *get_lb_size(const char *fmt, int *val) return fmt + 1; }
- GP_WARN("Invalid little/big endian variable size '%i'", *val); + GP_BUG("Invalid little/big endian variable size '%i'", *val); return NULL; }
@@ -143,7 +150,7 @@ static const char *get_next(const char *fmt, int *type, int *val) return NULL;
if (fmt[0] != '%') { - GP_WARN("Unexpected character in format string '%c'", fmt[0]); + GP_BUG("Unexpected character in format string '%c'", fmt[0]); return NULL; }
@@ -166,21 +173,48 @@ static const char *get_next(const char *fmt, int *type, int *val) return get_lb_size(fmt + 2, val); break; case 'i': - + *type = IGNORE; + return get_int(fmt + 2, val); break; case '0': - GP_WARN("Unexpecned end of format string"); + GP_BUG("Unexpecned end of format string"); return NULL; break; }
- GP_WARN("Unexpected character in format string '%c'", fmt[0]); + GP_BUG("Unexpected character in format string '%c'", fmt[0]); return NULL; }
+static void swap_bytes(void *ptr, int len, int type) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN && type == LITTLE_ENDIAN_VAR) + return; + + if (__BYTE_ORDER == __BIG_ENDIAN && type == BIG_ENDIAN_VAR) + return; + + char *buf = ptr; + + switch (len) { + case 1: + break; + case 2: + GP_SWAP(buf[0], buf[1]); + break; + case 4: + GP_SWAP(buf[0], buf[3]); + GP_SWAP(buf[1], buf[2]); + break; + default: + GP_BUG("Invalid size %i", len); + } +} + int GP_FRead(FILE *f, const char *fmt, ...) { int type, val, ret = 0; + void *ptr; va_list va;
va_start(va, fmt); @@ -203,13 +237,20 @@ int GP_FRead(FILE *f, const char *fmt, ...) break; case LITTLE_ENDIAN_VAR: case BIG_ENDIAN_VAR: - if (fread(va_arg(va, void*), val, 1, f) != 1) + ptr = va_arg(va, void*); + + if (fread(ptr, val, 1, f) != 1) goto end; - //TODO: Fix byteorder + + swap_bytes(ptr, val, type); break; case IGNORE: - + while (val--) + fgetc(f); break; + default: + GP_BUG("Wrong format type for reading (%i)", type); + goto end; } ret++; @@ -224,6 +265,9 @@ int GP_FWrite(FILE *f, const char *fmt, ...) { int type, val, ret = 0; va_list va; + uint8_t u8; + uint16_t u16; + uint32_t u32;
va_start(va, fmt);
@@ -246,25 +290,31 @@ int GP_FWrite(FILE *f, const char *fmt, ...) case LITTLE_ENDIAN_VAR: case BIG_ENDIAN_VAR: switch (val) { - case 1: { - uint8_t c = va_arg(va, int); - if (fwrite(&c, 1, 1, f) != 1) + case 1: + u8 = va_arg(va, int); + if (fwrite(&u8, 1, 1, f) != 1) goto end; - } break; - case 2: { - uint16_t c = va_arg(va, int); - if (fwrite(&c, 2, 1, f) != 1) + break; + case 2: + u16 = va_arg(va, int); + + swap_bytes(&u16, 2, type); + + if (fwrite(&u16, 2, 1, f) != 1) goto end; - } break; - case 4: { - uint32_t c = va_arg(va, int); - if (fwrite(&c, 4, 1, f) != 1) + break; + case 4: + u32 = va_arg(va, int); + + swap_bytes(&u32, 4, type); + + if (fwrite(&u32, 4, 1, f) != 1) goto end; - } break; + break; } break; default: - GP_WARN("Wrong format type for writing"); + GP_BUG("Wrong format type for writing (%i)", type); goto end; }
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/byte_utils.c | 6 +- include/loaders/GP_ByteUtils.h | 16 +++-- libs/core/GP_Context.c | 6 ++ libs/loaders/GP_BMP.c | 25 ++++--- libs/loaders/GP_ByteUtils.c | 155 ++++++++++++++++++++++++++-------------- tests/core/Context.c | 44 +++++++++++- 6 files changed, 177 insertions(+), 75 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.