summaryrefslogtreecommitdiffstats
path: root/src/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/text.c b/src/text.c
index f5ddaba..b288043 100644
--- a/src/text.c
+++ b/src/text.c
@@ -21,6 +21,7 @@
#include "text.h"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -47,6 +48,10 @@ _getc(struct text *text, FILE *stream, unsigned char *c)
{
int i_c;
+ assert(text);
+ assert(stream);
+ assert(c);
+
if (text->read == text->size) {
text->size += 8192;
text->string = realloc(text->string, text->size);
@@ -67,9 +72,8 @@ text_new(FILE *stream)
int eol;
unsigned char c;
- if (!stream) {
- return NULL;
- }
+ assert(stream);
+
text = calloc(1, sizeof(*text));
if (!text) {
error(_("Cannot allocate memory for text object"));
@@ -114,24 +118,34 @@ text_new(FILE *stream)
size_t
text_get_width(const struct text *text)
{
+ assert(text);
+
return text->width;
}
size_t
text_get_height(const struct text *text)
{
+ assert(text);
+
return text->height;
}
size_t
text_set_width(struct text *text, size_t width)
{
+ assert(text);
+ assert(width > 0);
+
return text->width = MAX(text->width, width);
}
size_t
text_set_height(struct text *text, size_t height)
{
+ assert(text);
+ assert(height > 0);
+
return text->height = MAX(text->height, height);
}
@@ -146,6 +160,10 @@ text_render(const struct text *text, const struct font *font, png_bytepp rows)
png_color fg = {170, 170, 170};
png_color bg = { 0, 0, 0};
+ assert(text);
+ assert(font);
+ assert(rows);
+
string_start = calloc(strlen((char *) text->string) + 1,
sizeof(*text->string));
if (!string_start) {
@@ -198,6 +216,8 @@ text_destroy(struct text **text_p)
{
struct text *text;
+ assert(text_p && *text_p);
+
text = *text_p;
free(text->string);