commit b2cb0475d443775aca17b136b34d6cf2abcc228a
parent 1147430d78e6c35fecaf02a3ed8d461bb18de376
Author: Santtu Lakkala <inz@inz.fi>
Date: Fri, 31 Jan 2025 13:55:06 +0200
Make more standards compilant
Diffstat:
7 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,7 @@
+.POSIX:
PREFIX?=/usr/local
PREFIX_MAN=$(PREFIX)/man
-CFLAGS?=-g -Wall -Wextra -pedantic
+CFLAGS=-std=c99 -Os -Wall -Wextra -pedantic -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=500
all: snac
@@ -80,3 +81,5 @@ utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h
webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \
http_codes.h
+
+.SUFFIXES: .c .o
diff --git a/data.c b/data.c
@@ -1513,7 +1513,7 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list)
while (xs_list_next(list, &v, &c)) {
char line[MD5_HEX_SIZE] = "";
- strncpy(line, v, sizeof(line));
+ strncpy(line, v, sizeof(line) - 1);
for (;;) {
char line2[MD5_HEX_SIZE];
@@ -1527,7 +1527,7 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list)
break;
/* it's here! try again with its own parent */
- strncpy(line, line2, sizeof(line));
+ memcpy(line, line2, sizeof(line));
}
xs_set_add(&seen, line);
diff --git a/httpd.c b/httpd.c
@@ -20,6 +20,7 @@
#include <semaphore.h>
#include <fcntl.h>
#include <stdint.h>
+#include <unistd.h>
#include <sys/resource.h> // for getrlimit()
diff --git a/mastoapi.c b/mastoapi.c
@@ -2360,10 +2360,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
xs *des = xs_list_new();
xs_list *p;
const xs_str *v;
- char pid[MD5_HEX_SIZE];
+ char pid[MD5_HEX_SIZE] = "";
/* build the [grand]parent list, moving up */
- strncpy(pid, id, sizeof(pid));
+ strncpy(pid, id, sizeof(pid) - 1);
while (object_parent(pid, pid)) {
xs *m2 = NULL;
diff --git a/xs_fcgi.h b/xs_fcgi.h
@@ -92,7 +92,7 @@ xs_dict *xs_fcgi_request(FILE *f, xs_str **payload, int *p_size, int *fcgi_id)
*fcgi_id = -1;
for (;;) {
- int sz, psz;
+ int psz;
/* read the packet header */
if (fread(&hdr, sizeof(hdr), 1, f) != 1)
@@ -100,13 +100,13 @@ xs_dict *xs_fcgi_request(FILE *f, xs_str **payload, int *p_size, int *fcgi_id)
/* read the packet body */
if ((psz = ntohs(hdr.content_len)) > 0) {
- if ((sz = fread(p_buf, 1, psz, f)) != psz)
+ if (fread(p_buf, 1, psz, f) != (size_t)psz)
break;
}
/* read (and drop) the padding */
if (hdr.padding_len > 0)
- fread(p_buf + sz, 1, hdr.padding_len, f);
+ fread(p_buf + psz, 1, hdr.padding_len, f);
switch (hdr.type) {
case FCGI_BEGIN_REQUEST:
diff --git a/xs_match.h b/xs_match.h
@@ -17,7 +17,7 @@ int xs_match(const char *str, const char *spec);
int xs_match(const char *str, const char *spec)
{
- const char *b_str;
+ const char *b_str = NULL;
const char *b_spec = NULL;
const char *o_str = str;
diff --git a/xs_regex.h b/xs_regex.h
@@ -35,7 +35,7 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
regmatch_t rm;
int offset = 0;
xs_list *list = xs_list_new();
- const char *p;
+ const char *p = str;
if (regcomp(&re, rx, REG_EXTENDED))
return list;