Skip to content

Commit

Permalink
Merge pull request #129 from MisterDA/compiler-warnings
Browse files Browse the repository at this point in the history
Add and fix C compiler warnings
  • Loading branch information
dra27 authored Jul 3, 2024
2 parents 5719f5a + 1eb6737 commit 80496b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ COMPAT_VERSION:=$(subst ., ,$(OCAML_VERSION))
COMPAT_VERSION:=$(subst $(SPACE),,$(firstword $(COMPAT_VERSION))$(foreach i,$(wordlist 2,$(words $(COMPAT_VERSION)),$(COMPAT_VERSION)),$(if $(filter 0 1 2 3 4 5 6 7 8 9,$(i)),0,)$(i)))
endif

GCC_FLAGS = -Wall

MINGW_PREFIX = i686-w64-mingw32-
MINCC = $(MINGW_PREFIX)gcc
MINCC = $(MINGW_PREFIX)gcc $(GCC_FLAGS)

MINGW64_PREFIX = x86_64-w64-mingw32-
MIN64CC = $(MINGW64_PREFIX)gcc
MIN64CC = $(MINGW64_PREFIX)gcc $(GCC_FLAGS)

CYGWIN64_PREFIX = x86_64-pc-cygwin-
CYG64CC = $(CYGWIN64_PREFIX)gcc
CYG64CC = $(CYGWIN64_PREFIX)gcc $(GCC_FLAGS)

version.ml: Makefile flexdll.opam
echo "let version = \"$(VERSION)\"" > version.ml
Expand All @@ -60,7 +62,7 @@ endif
Makefile.winsdk: msvs-detect
bash ./msvs-detect --output=make > $@

MSVC_FLAGS=/nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS-
MSVC_FLAGS = /nologo /MD -D_CRT_SECURE_NO_DEPRECATE /GS- /W3

ifeq ($(MSVC_DETECT),0)
# Assume that the environment is correctly set for a single Microsoft C Compiler; don't attempt to guess anything
Expand Down Expand Up @@ -95,6 +97,12 @@ MSVCC64 = cl.exe $(MSVC_FLAGS)
endif
endif

FLEXDLL_WARN_ERROR ?=
ifeq ($(FLEXDLL_WARN_ERROR),true)
GCC_FLAGS += -Werror -fdiagnostics-color=always
MSVC_FLAGS += /WX
endif

show_root:
ifeq ($(MSVCC_ROOT),)
@echo "$(MSVS_PATH)"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:
OCAML_PORT: msvc64
ARTEFACTS: no
FLEXDLL_VERSION: 0.43
FLEXDLL_WARN_ERROR: true
matrix:
- OCAMLBRANCH: 3.11
- OCAMLBRANCH: 3.12
Expand Down
20 changes: 10 additions & 10 deletions flexdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,15 @@ static void dump_master_reloctbl(reloctbl **ptr) {
/* Avoid the use of snprintf */
static void cannot_resolve_msg(char *name, err_t *err) {
static char msg[] = "Cannot resolve ";
static int l = sizeof(msg) - 1;
int n = strlen(name);
static size_t l = sizeof(msg) - 1;
size_t n = strlen(name);
memcpy(err->message,msg,l);
memcpy(err->message+l,name,min(n,sizeof(err->message) - l - 1));
err->message[l+n] = 0;
}

static void relocate(resolver f, void *data, reloctbl *tbl, err_t *err) {
reloc_entry *ptr;
nonwr *wr;
INT_PTR s;
DWORD prev_protect;
static long int page_size = 0;
Expand Down Expand Up @@ -325,7 +324,7 @@ static void relocate(resolver f, void *data, reloctbl *tbl, err_t *err) {
err->code = 3;
goto restore;
}
*((UINT32*) ptr->addr) = s;
*((UINT32*) ptr->addr) = (INT32) s;
break;
case RELOC_REL32_4:
s -= (INT_PTR)(ptr -> addr) + 8;
Expand All @@ -335,7 +334,7 @@ static void relocate(resolver f, void *data, reloctbl *tbl, err_t *err) {
err->code = 3;
goto restore;
}
*((UINT32*) ptr->addr) = s;
*((UINT32*) ptr->addr) = (INT32) s;
break;
case RELOC_REL32_1:
s -= (INT_PTR)(ptr -> addr) + 5;
Expand All @@ -345,7 +344,7 @@ static void relocate(resolver f, void *data, reloctbl *tbl, err_t *err) {
err->code = 3;
goto restore;
}
*((UINT32*) ptr->addr) = s;
*((UINT32*) ptr->addr) = (INT32) s;
break;
case RELOC_REL32_2:
s -= (INT_PTR)(ptr -> addr) + 6;
Expand All @@ -355,7 +354,7 @@ static void relocate(resolver f, void *data, reloctbl *tbl, err_t *err) {
err->code = 3;
goto restore;
}
*((UINT32*) ptr->addr) = s;
*((UINT32*) ptr->addr) = (INT32) s;
break;
default:
fprintf(stderr, "flexdll: unknown relocation kind");
Expand All @@ -381,13 +380,13 @@ static void relocate_master(resolver f, void *data, reloctbl **ptr, err_t *err)

static void dump_symtbl(symtbl *tbl)
{
int i;
unsigned i;

if (!tbl) { printf("No symbol table\n"); return; }
printf("Dynamic symbol at %p (size = %u)\n", tbl, (unsigned int) tbl->size); fflush(stdout);

for (i = 0; i < tbl->size; i++) {
printf("[%i] ", i); fflush(stdout);
printf("[%u] ", i); fflush(stdout);
printf(" %p: ", tbl->entries[i].addr); fflush(stdout);
printf("%s\n", tbl->entries[i].name);
fflush(stdout);
Expand Down Expand Up @@ -436,6 +435,7 @@ static void unlink_unit(dlunit *unit) {
static void *find_symbol_global(void *data, const char *name) {
void *sym;
dlunit *unit;
(void)data; /* data is unused */

if (!name) return NULL;
sym = find_symbol(&static_symtable, name);
Expand Down Expand Up @@ -597,7 +597,7 @@ void *flexdll_dlsym(void *u, const char *name) {
return res;
}

char *flexdll_dlerror() {
char *flexdll_dlerror(void) {
err_t * err;
err = get_tls_error(TLS_ERROR_NOP);
if(err == NULL) return TLS_ACCESS_ERRMSG;
Expand Down
1 change: 0 additions & 1 deletion test/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void api2(char *msg){ printf("API2: %s\n", msg); }

int main(int argc, char **argv)
{
void *sym;
void *handle;
int i;
torun *torun;
Expand Down

0 comments on commit 80496b5

Please sign in to comment.