From 67a16319c6fdf00936bfd5e3bdf629b8c85d0036 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 10 Nov 2003 18:29:04 +0000 Subject: [PATCH] * libee/sprite.c: + Added sanity checks in ee_sprite_* functions. * libee/conic.c: + Use ellipsepoints() in ee_draw_circle(). --- libee/conic.c | 29 ++++++++++++----------------- libee/sprite.c | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/libee/conic.c b/libee/conic.c index 7bc05aa..d9e137b 100644 --- a/libee/conic.c +++ b/libee/conic.c @@ -26,6 +26,8 @@ #include "ee.h" +static void ellipsepoints(int, int, int, int, char); + void ee_draw_circle(int x, int y, int r, char c) { int test, dx, dy; @@ -33,28 +35,13 @@ void ee_draw_circle(int x, int y, int r, char c) /* Optimized Bresenham. Kick ass. */ for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) { - ee_putcharTO(x + dx, y + dy / 2, c); - ee_putcharTO(x - dx, y + dy / 2, c); - ee_putcharTO(x + dx, y - dy / 2, c); - ee_putcharTO(x - dx, y - dy / 2, c); - - ee_putcharTO(x + dy, y + dx / 2, c); - ee_putcharTO(x - dy, y + dx / 2, c); - ee_putcharTO(x + dy, y - dx / 2, c); - ee_putcharTO(x - dy, y - dx / 2, c); + ellipsepoints(x, y, dx, dy, c); + ellipsepoints(x, y, dy, dx, c); test += test > 0 ? dx - dy-- : dx; } } -static void ellipsepoints(int xo, int yo, int x, int y, char c) -{ - ee_putcharTO(xo + x, yo + y, c); - ee_putcharTO(xo - x, yo + y, c); - ee_putcharTO(xo + x, yo - y, c); - ee_putcharTO(xo - x, yo - y, c); -} - void ee_draw_ellipse(int xo, int yo, int a, int b, char c) { int d2; @@ -97,3 +84,11 @@ void ee_draw_ellipse(int xo, int yo, int a, int b, char c) } } +static void ellipsepoints(int xo, int yo, int x, int y, char c) +{ + ee_putcharTO(xo + x, yo + y, c); + ee_putcharTO(xo - x, yo + y, c); + ee_putcharTO(xo + x, yo - y, c); + ee_putcharTO(xo - x, yo - y, c); +} + diff --git a/libee/sprite.c b/libee/sprite.c index e1187e3..78fcb4f 100644 --- a/libee/sprite.c +++ b/libee/sprite.c @@ -130,6 +130,9 @@ struct ee_sprite *ee_load_sprite(const char *file) void ee_set_sprite_frame(struct ee_sprite *sprite, int f) { + if(sprite == NULL) + return; + if(f < 0 || f >= sprite->nf) return; @@ -138,13 +141,21 @@ void ee_set_sprite_frame(struct ee_sprite *sprite, int f) int ee_get_sprite_frame(struct ee_sprite *sprite) { + if(sprite == NULL) + return -1; + return sprite->f; } void ee_draw_sprite(int x, int y, struct ee_sprite *sprite) { int i, j; - struct ee_frame *frame = &sprite->frames[sprite->f]; + struct ee_frame *frame; + + if(sprite == NULL) + return; + + frame = &sprite->frames[sprite->f]; for(j = 0; j < frame->h; j++) { @@ -165,6 +176,9 @@ void ee_free_sprite(struct ee_sprite *sprite) { int i; + if(sprite == NULL) + return; + for(i = sprite->nf; i--;) { struct ee_frame *frame = &sprite->frames[i];