Skip to content

Commit 6393819

Browse files
author
newnix
committed
Fix Building on Ubuntu, Logic Errors
* Makefile - Since GNU make and BSD make treat `$<` differently, switch to using `${OBJ}` macro for the `$(PROJECT)` target * clang-opts.mk - Add `-Wno-reserved-id-macro` to `WRN` macro * initdb.c - Ensure proper NUL termination when trying to `stat(2)` the directory given to initialize the database in * nombre.c - Correct Linux detection macro * parsecmd.c - Fix control flow issue for group operations in `nombre_newdef()`, correctly detecting when an invalid number of arguments were given * subnom.c - Added macro to determine correct format string for printing definitions based on host platform
1 parent 1054c4c commit 6393819

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ subnom.o: nombre.h initdb.h parsecmd.h subnom.h
6363
dbverify.o: nombre.h dbverify.h
6464

6565
$(PROJECT): $(OBJ)
66-
@$(CC) -o $@ $> -fuse-ld=${LD} ${LDFLAGS}
66+
@$(CC) -o $@ ${OBJ} -fuse-ld=${LD} ${LDFLAGS}
6767

6868
help:
6969
@printf "Build options for %s\n" "${PROJECT}"

clang-opts.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CC = clang
33
LD = lld
44

55
WRN = -Wextra -Wall -Weverything -Wdeprecated -pedantic -Werror -Wno-padded -Wno-cast-qual -Wno-unused-command-line-argument\
6-
-Wno-disabled-macro-expansion
6+
-Wno-disabled-macro-expansion -Wno-reserved-id-macro
77
CFLAGS = ${WRN} ${MACRO_OVERRIDES} -std=${STD} -Oz -fpic -fpie -pipe -fPIC -fPIE -fvectorize -fstack-protector \
88
-fstrict-enums -fstrict-return -fstack-protector-strong -fmerge-all-constants -fstack-protector-all \
99
-Qn -fstrict-aliasing -ffunction-sections -fdata-sections -fuse-ld=${LD}

initdb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ nom_dirtest(const char * dbname, const size_t dbnamelen) {
184184
while (dirsep --> 0) {
185185
if ((dbname[dirsep] ^ DIRSEP) == 0) {
186186
memccpy(dbdir, dbname, 0, (size_t)(dirsep + 1)); /* dbdir should now have the directory info from the specified path */
187+
dbdir[dirsep] = 0; /* Ensure proper NUL termination */
187188
if (dbg) { NOMDBG("Captured %s as the nombre DB directory\n", dbdir); }
188189
userid = getuid();
189190
/* Group info tests could be improved, currently just using the primary GID */

nombre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <stdint.h>
3838
#include <stdlib.h>
3939
#include <string.h>
40-
#ifdef LINUX
40+
#if defined(__linux__)
4141
#include <bsd/string.h>
4242
#endif /* end LINUX */
4343
#include <unistd.h>

parsecmd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ nombre_newdef(nomcmd * restrict cmdbuf, const char ** restrict args) {
195195
retc = snprintf(cmdbuf->gensql, (size_t)PATHMAX,
196196
"INSERT INTO definitions VALUES (\'%s\', \'%s\', (SELECT id FROM categories WHERE name LIKE(\'%s\')));",
197197
cmdbuf->defdata[NOMBRE_DBTERM], defstr, cmdbuf->defdata[NOMBRE_DBCATG]);
198+
} else {
199+
retc = BADARGS;
200+
NOMERR("Invalid number of arguments for %s!\n", __func__);
198201
}
199-
retc = BADARGS;
200-
NOMERR("Invalid number of arguments for %s!\n", __func__);
201202
} else {
202203
memccpy(cmdbuf->defdata[NOMBRE_DBTERM], *args, 0, (size_t)DEFLEN); args++;
203204
upcase(cmdbuf->defdata[NOMBRE_DBTERM]);

subnom.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ runcmd(nomcmd * restrict cmdbuf, int genlen) {
190190
}
191191
for (register uint_fast16_t i = 1; retc == SQLITE_ROW; i++, retc = sqlite3_step(stmt)) {
192192
if (i > 1) {
193-
fprintf(stdout," #%d: %s\n", i, sqlite3_column_text(stmt,0));
193+
/* Because the size here is apparently inconsistent across platforms */
194+
#if defined(__linux__)
195+
fprintf(stdout," #%zu: %s\n", i, sqlite3_column_text(stmt,0));
196+
#else
197+
fprintf(stdout," #%u: %s\n", i, sqlite3_column_text(stmt,0));
198+
#endif
194199
} else {
195200
fprintf(stdout,"%s: %s\n", cmdbuf->defdata[NOMBRE_DBTERM], sqlite3_column_text(stmt,0));
196201
}

0 commit comments

Comments
 (0)