summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 19:43:06 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 19:43:06 (EDT)
commit373c9218245263fe986f4b93ef62cfa9af6c644b (patch)
tree4db01ec2d312879e9810060c50a816a992343c44
parent8225911a9c19f5c738397488ccebf510490536f3 (diff)
assert() function arguments
-rw-r--r--src/font.c14
-rw-r--r--src/image.c9
-rw-r--r--src/output.c5
-rw-r--r--src/sgr.c5
-rw-r--r--src/text.c26
5 files changed, 56 insertions, 3 deletions
diff --git a/src/font.c b/src/font.c
index 719d7ff..d333189 100644
--- a/src/font.c
+++ b/src/font.c
@@ -21,6 +21,7 @@
#include "font.h"
+#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
@@ -53,6 +54,8 @@ font_list(FILE *stream)
{
size_t i;
+ assert(stream);
+
for (i = 0; i < *(&fonts + 1) - fonts; ++i) {
fprintf(stream, "%s\n", fonts[i]->name);
}
@@ -81,6 +84,8 @@ font_find(const char *name)
{
size_t i;
+ assert(name);
+
if (!name) {
return NULL;
}
@@ -96,12 +101,16 @@ font_find(const char *name)
int
font_get_width(const struct font *font)
{
+ assert(font);
+
return font->desc.width;
}
int
font_get_height(const struct font *font)
{
+ assert(font);
+
return font->desc.height;
}
@@ -116,6 +125,11 @@ font_render(const struct font *font, png_const_colorp fg, png_const_colorp bg,
size_t byte;
unsigned char font_ch;
+ assert(font);
+ assert(fg);
+ assert(bg);
+ assert(rows && *rows);
+
for (y = 0, r = row * FONT_H(font); y < FONT_H(font); ++y, ++r) {
for (x = 0, c = col * FONT_W(font); x < FONT_W(font); ++x, ++c){
byte = ((ch * FONT_H(font)) + y) * FONT_W_BYTES(font) +
diff --git a/src/image.c b/src/image.c
index 47bc94c..626ffa7 100644
--- a/src/image.c
+++ b/src/image.c
@@ -21,6 +21,7 @@
#include "image.h"
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -42,6 +43,8 @@ image_new(const char *file_name)
{
struct image *image;
+ assert(file_name && *file_name);
+
image = calloc(1, sizeof(*image));
if (!image) {
error(_("Cannot allocate memory for image object"));
@@ -87,6 +90,10 @@ image_render(struct image *image, const struct text *text,
png_bytepp rows;
size_t i;
+ assert(image);
+ assert(text);
+ assert(font);
+
width = text_get_width(text) * font_get_width(font);
height = text_get_height(text) * font_get_height(font);
@@ -116,6 +123,8 @@ image_destroy(struct image **image_p)
{
struct image *image;
+ assert(image_p && *image_p);
+
image = *image_p;
if (image->fp) {
diff --git a/src/output.c b/src/output.c
index 0d8341c..77bda63 100644
--- a/src/output.c
+++ b/src/output.c
@@ -21,6 +21,7 @@
#include "output.h"
+#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
@@ -31,6 +32,8 @@ static const char *_program_name;
void
set_program_name(const char *name)
{
+ assert(name && *name);
+
_program_name = name;
}
@@ -39,6 +42,8 @@ error(const char *format, ...)
{
va_list ap;
+ assert(format);
+
fprintf(stderr, _("%s: Error: "), _program_name);
va_start(ap, format);
vfprintf(stderr, format, ap);
diff --git a/src/sgr.c b/src/sgr.c
index 4017b72..b768e96 100644
--- a/src/sgr.c
+++ b/src/sgr.c
@@ -21,6 +21,7 @@
#include "sgr.h"
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -57,6 +58,10 @@ sgr(unsigned char *param, png_colorp fg, png_colorp bg)
unsigned char *p;
int i;
+ assert(param);
+ assert(fg);
+ assert(bg);
+
end = 0;
for (p = param; param; ++param) {
if (*param == ';' || *param == ':' || *param == '\0') {
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);