Skip to content

Commit

Permalink
Add warning flags to make debug, and refactor to not print any warn…
Browse files Browse the repository at this point in the history
…ings (#4)

* Add warning flags to `make debug`, and refactor to not print any warnings
* Add `-fanalyzer` to `make debug`
* Address PR comments
  • Loading branch information
Rangi42 authored Jan 15, 2022
1 parent f309a18 commit d309485
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 34 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
CC ?= gcc
OUTPUT ?= libplum.so
OPTFLAGS = -march=native -mtune=native
DEBUGFLAGS =

CFLAGS = -Ofast -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-exceptions -Wl,-S -Wl,-x -Wl,--gc-sections \
$(OPTFLAGS)
CFLAGS = -std=c17 -Ofast -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-exceptions -Wl,-S -Wl,-x -Wl,--gc-sections $(OPTFLAGS)

DEBUGFLAGS = -Wall -Wextra -pedantic -Wcast-align -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshadow -Wshift-overflow=2 -Wundef \
-Wunused -Wwrite-strings -Wno-sign-compare -Wno-implicit-fallthrough -Wno-parentheses -Wno-dangling-else -fanalyzer -fanalyzer-verbosity=0

.PHONY: all clean basefiles debug

all: basefiles
$(CC) -shared -fPIC $(CFLAGS) build/libplum.c -o build/$(OUTPUT)
Expand Down
3 changes: 2 additions & 1 deletion src/bmpread.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ uint64_t load_BMP_word_pixel (const unsigned char * data, const void * bitmasks)
return load_BMP_bitmasked_pixel(read_le32_unaligned(data), bitmasks);
}

uint64_t load_BMP_RGB_pixel (const unsigned char * data, const void * unused) {
uint64_t load_BMP_RGB_pixel (const unsigned char * data, const void * bitmasks) {
(void) bitmasks;
return (((uint64_t) *data << 32) | ((uint64_t) data[1] << 16) | (uint64_t) data[2]) * 0x101;
}

Expand Down
2 changes: 1 addition & 1 deletion src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int image_has_transparency (const struct plum_image * image) {
while (count --) if (*(color ++) >= 0x7fff) return 1;
return 0;
}
case PLUM_COLOR_32X: {
default: { // PLUM_COLOR_32X
const uint32_t * color = colordata;
if (image -> color_format & PLUM_ALPHA_INVERT) {
while (count --) if (*(color ++) < 0xc0000000u) return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define bytematch(address, ...) (!memcmp((address), (unsigned char []) {__VA_ARGS__}, sizeof (unsigned char []) {__VA_ARGS__}))
#define byteoutput(context, ...) (memcpy(append_output_node((context), sizeof (unsigned char []) {__VA_ARGS__}), \
(unsigned char []) {__VA_ARGS__}, sizeof (unsigned char []) {__VA_ARGS__}))
#define bytewrite(address, ...) (memcpy(address, (unsigned char []) {__VA_ARGS__}, sizeof (unsigned char []) {__VA_ARGS__}), \
sizeof (unsigned char []) {__VA_ARGS__})
#define bytewrite(address, ...) (memcpy(address, (unsigned char []) {__VA_ARGS__}, sizeof (unsigned char []) {__VA_ARGS__}))
#define byteappend(address, ...) (bytewrite(address, __VA_ARGS__), sizeof (unsigned char []) {__VA_ARGS__})

#endif
3 changes: 3 additions & 0 deletions src/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ ROTATE_FRAME_FUNCTION(64)
#undef ROTATE_FRAME_FUNCTION

size_t rotate_left_coordinate (size_t row, size_t col, size_t width, size_t height) {
(void) width;
return (col + 1) * height - (row + 1);
}

Expand All @@ -147,6 +148,7 @@ size_t flip_coordinate (size_t row, size_t col, size_t width, size_t height) {
}

size_t rotate_left_flip_coordinate (size_t row, size_t col, size_t width, size_t height) {
(void) width;
return col * height + row;
}

Expand All @@ -155,5 +157,6 @@ size_t rotate_right_flip_coordinate (size_t row, size_t col, size_t width, size_
}

size_t rotate_both_flip_coordinate (size_t row, size_t col, size_t width, size_t height) {
(void) height;
return (row + 1) * width - (col + 1);
}
21 changes: 11 additions & 10 deletions src/jpeghierarchical.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ unsigned load_hierarchical_JPEG (struct context * context, const struct JPEG_mar
double * data = output[frameIDs[p]];
for (index = 0; index < limit; index ++) data[index] = (uint16_t) ((long) (data[index] + 65536.5)); // avoid UB and round negative values correctly
}
double * buffer = NULL;
if (expand) buffer = ctxmalloc(context, sizeof *buffer * framewidth * frameheight);
if (expand & 0x10) for (p = 0; p < framecount; p ++) {
expand_JPEG_component_horizontally(context, output[frameIDs[p]], component_size[frameIDs[p]], component_size[frameIDs[p] + 4], framewidth, buffer);
component_size[frameIDs[p]] = framewidth;
}
if (expand & 1) for (p = 0; p < framecount; p ++) {
expand_JPEG_component_vertically(context, output[frameIDs[p]], component_size[frameIDs[p]], component_size[frameIDs[p] + 4], frameheight, buffer);
component_size[frameIDs[p] + 4] = frameheight;
if (expand) {
double * buffer = ctxmalloc(context, sizeof *buffer * framewidth * frameheight);
if (expand & 0x10) for (p = 0; p < framecount; p ++) {
expand_JPEG_component_horizontally(context, output[frameIDs[p]], component_size[frameIDs[p]], component_size[frameIDs[p] + 4], framewidth, buffer);
component_size[frameIDs[p]] = framewidth;
}
if (expand & 1) for (p = 0; p < framecount; p ++) {
expand_JPEG_component_vertically(context, output[frameIDs[p]], component_size[frameIDs[p]], component_size[frameIDs[p] + 4], frameheight, buffer);
component_size[frameIDs[p] + 4] = frameheight;
}
ctxfree(context, buffer);
}
ctxfree(context, buffer);
for (p = 0; p < framecount; p ++) if ((component_size[frameIDs[p]] != framewidth) || (component_size[frameIDs[p] + 4] != frameheight))
throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void load_file (struct context * context, const char * filename) {

void load_from_callback (struct context * context, const struct plum_callback * callback) {
size_t allocated;
char * buffer = resize_read_buffer(context, NULL, &allocated);
unsigned char * buffer = resize_read_buffer(context, NULL, &allocated);
int iteration = callback -> callback(callback -> userdata, buffer, 0x4000 - sizeof(union allocator_node));
if ((iteration < 0) || (iteration > (0x4000 - sizeof(union allocator_node)))) throw(context, PLUM_ERR_FILE_ERROR);
context -> size = iteration;
Expand Down
28 changes: 14 additions & 14 deletions src/pnmwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void generate_PPM_data (struct context * context, const uint32_t * sizes, unsign

void generate_PPM_header (struct context * context, uint32_t width, uint32_t height, unsigned bitdepth) {
unsigned char * node = append_output_node(context, 32);
size_t offset = bytewrite(node, 0x50, 0x36, 0x0a); // P6<newline>
size_t offset = byteappend(node, 0x50, 0x36, 0x0a); // P6<newline>
offset += write_PNM_number(node + offset, width);
node[offset ++] = 0x20; // space
offset += write_PNM_number(node + offset, height);
Expand All @@ -146,22 +146,22 @@ void generate_PAM_data (struct context * context, unsigned bitdepth, uint64_t *

void generate_PAM_header (struct context * context, unsigned bitdepth) {
unsigned char * node = append_output_node(context, 96);
size_t offset = bytewrite(node,
0x50, 0x37, 0x0a, // P7<newline>
0x54, 0x55, 0x50, 0x4c, 0x54, 0x59, 0x50, 0x45, 0x20, // TUPLTYPE<space>
0x52, 0x47, 0x42, 0x5f, 0x41, 0x4c, 0x50, 0x48, 0x41, 0x0a, // RGB_ALPHA<newline>
0x57, 0x49, 0x44, 0x54, 0x48, 0x20 // WIDTH<space>
);
size_t offset = byteappend(node,
0x50, 0x37, 0x0a, // P7<newline>
0x54, 0x55, 0x50, 0x4c, 0x54, 0x59, 0x50, 0x45, 0x20, // TUPLTYPE<space>
0x52, 0x47, 0x42, 0x5f, 0x41, 0x4c, 0x50, 0x48, 0x41, 0x0a, // RGB_ALPHA<newline>
0x57, 0x49, 0x44, 0x54, 0x48, 0x20 // WIDTH<space>
);
offset += write_PNM_number(node + offset, context -> source -> width);
offset += bytewrite(node + offset, 0x0a, 0x48, 0x45, 0x49, 0x47, 0x48, 0x54, 0x20); // <newline>HEIGHT<space>
offset += byteappend(node + offset, 0x0a, 0x48, 0x45, 0x49, 0x47, 0x48, 0x54, 0x20); // <newline>HEIGHT<space>
offset += write_PNM_number(node + offset, context -> source -> height);
offset += bytewrite(node + offset, 0x0a, 0x4d, 0x41, 0x58, 0x56, 0x41, 0x4c, 0x20); // <newline>MAXVAL<space>
offset += byteappend(node + offset, 0x0a, 0x4d, 0x41, 0x58, 0x56, 0x41, 0x4c, 0x20); // <newline>MAXVAL<space>
offset += write_PNM_number(node + offset, ((uint32_t) 1 << bitdepth) - 1);
offset += bytewrite(node + offset,
0x0a, // <newline>
0x44, 0x45, 0x50, 0x54, 0x48, 0x20, 0x34, 0x0a, // DEPTH 4<newline>
0x45, 0x4e, 0x44, 0x48, 0x44, 0x52, 0x0a // ENDHDR<newline>
);
offset += byteappend(node + offset,
0x0a, // <newline>
0x44, 0x45, 0x50, 0x54, 0x48, 0x20, 0x34, 0x0a, // DEPTH 4<newline>
0x45, 0x4e, 0x44, 0x48, 0x44, 0x52, 0x0a // ENDHDR<newline>
);
context -> output -> size = offset;
}

Expand Down
4 changes: 2 additions & 2 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void write_generated_image_data_to_file (struct context * context, const char *
const struct data_node * node;
for (node = context -> output; node -> previous; node = node -> previous);
while (node) {
const char * data = node -> data;
const unsigned char * data = node -> data;
size_t size = node -> size;
while (size) {
unsigned count = fwrite(data, 1, (size > 0x4000) ? 0x4000 : size, fp);
Expand All @@ -73,7 +73,7 @@ void write_generated_image_data_to_callback (struct context * context, const str
struct data_node * node;
for (node = context -> output; node -> previous; node = node -> previous);
while (node) {
char * data = node -> data;
unsigned char * data = node -> data;
size_t size = node -> size;
while (size) {
int count = callback -> callback(callback -> userdata, data, (size > 0x4000) ? 0x4000 : size);
Expand Down

0 comments on commit d309485

Please sign in to comment.