From 1685f11b87ec7454028fb2d0038a080aa95e9cff Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Nov 2023 18:25:11 -0800 Subject: [PATCH 1/3] replace index with strchr The former is deprecated and unavailable if POSIX_C_SOUCE==200811L. Signed-off-by: Rosen Penev --- src/backend.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend.c b/src/backend.c index f7c916e1d..c2e3e0a21 100644 --- a/src/backend.c +++ b/src/backend.c @@ -7472,11 +7472,11 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) #if defined (__APPLE__) - char *start130 = index (device_param->opencl_driver_version, '('); - char *stop130 = index (device_param->opencl_driver_version, ')'); + char *start130 = strchr (device_param->opencl_driver_version, '('); + char *stop130 = strchr (device_param->opencl_driver_version, ')'); - char *start131 = index (opencl_platform_version, '('); - char *stop131 = index (opencl_platform_version, ')'); + char *start131 = strchr (opencl_platform_version, '('); + char *stop131 = strchr (opencl_platform_version, ')'); // either none or one of these have a date string From 6aaf0f3ac424ec0037a45132393491f08010cf95 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 8 Dec 2023 16:47:24 -0800 Subject: [PATCH 2/3] Fix compilation on newer FreeBSD Apparently qsort_r is a macro now. Check for it. Signed-off-by: Rosen Penev --- include/sort_r.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sort_r.h b/include/sort_r.h index 79bd8ab65..f9fb31360 100644 --- a/include/sort_r.h +++ b/include/sort_r.h @@ -138,7 +138,7 @@ static _SORT_R_INLINE void sort_r_simple(void *base, size_t nel, size_t w, /* Declare structs and functions */ - #if defined _SORT_R_BSD + #if defined _SORT_R_BSD && !defined(qsort_r) /* Ensure qsort_r is defined */ extern void qsort_r(void *base, size_t nel, size_t width, void *thunk, From cdd92f6de6cf8a314b0d4bf8aefcde78251ef4e3 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 8 Dec 2023 17:16:07 -0800 Subject: [PATCH 3/3] Fix MinGW printf formats Based on various compilation flags, MinGW uses either gnu_printf or printf (really ms_printf) internally which confuses the compiler when encountering gnu formats. OTOH, clang under MinGW does not support gnu_printf. Just use the macro to handle this mess. Also remove macro that was originally used to work around this. It's wrong and should not be used. Signed-off-by: Rosen Penev --- include/event.h | 22 +++++++++++++--------- include/logfile.h | 6 +++++- include/shared.h | 7 ++++++- src/Makefile | 1 - src/event.c | 6 +++++- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/event.h b/include/event.h index fca7eec55..4f9cfa0a7 100644 --- a/include/event.h +++ b/include/event.h @@ -14,15 +14,19 @@ void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, cons #define EVENT(id) event_call ((id), hashcat_ctx, NULL, 0) #define EVENT_DATA(id,buf,len) event_call ((id), hashcat_ctx, (buf), (len)) -__attribute__ ((format (printf, 2, 3))) size_t event_log_advice_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); - -__attribute__ ((format (printf, 2, 3))) size_t event_log_advice (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); -__attribute__ ((format (printf, 2, 3))) size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +#ifndef __MINGW_PRINTF_FORMAT +#define __MINGW_PRINTF_FORMAT printf +#endif + +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_advice_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); + +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_advice (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); int event_ctx_init (hashcat_ctx_t *hashcat_ctx); void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/logfile.h b/include/logfile.h index b3f3fb8d1..f154f6bb5 100644 --- a/include/logfile.h +++ b/include/logfile.h @@ -34,9 +34,13 @@ #define logfile_top_string(var) logfile_top_var_string (#var, (var)) #define logfile_sub_string(var) logfile_sub_var_string (#var, (var)) +#ifndef __MINGW_PRINTF_FORMAT +#define __MINGW_PRINTF_FORMAT printf +#endif + void logfile_generate_topid (hashcat_ctx_t *hashcat_ctx); void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx); -void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); +void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) __attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))); int logfile_init (hashcat_ctx_t *hashcat_ctx); void logfile_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/shared.h b/include/shared.h index f1660c58e..9bd47f18a 100644 --- a/include/shared.h +++ b/include/shared.h @@ -7,6 +7,7 @@ #define HC_SHARED_H #include +#include #include #include #include @@ -24,6 +25,10 @@ #include #endif +#ifndef __MINGW_PRINTF_FORMAT +#define __MINGW_PRINTF_FORMAT printf +#endif + int sort_by_string_sized (const void *p1, const void *p2); int sort_by_stringptr (const void *p1, const void *p2); @@ -44,7 +49,7 @@ char *filename_from_filepath (char *filepath); void naive_replace (char *s, const char key_char, const char replace_char); void naive_escape (char *s, size_t s_max, const char key_char, const char escape_char); -__attribute__ ((format (printf, 2, 3))) int hc_asprintf (char **strp, const char *fmt, ...); +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) int hc_asprintf (char **strp, const char *fmt, ...); void setup_environment_variables (const folder_config_t *folder_config); void setup_umask (void); diff --git a/src/Makefile b/src/Makefile index 1cd440645..a7eb7b985 100644 --- a/src/Makefile +++ b/src/Makefile @@ -750,7 +750,6 @@ CFLAGS_CROSS_WIN := $(CFLAGS) CFLAGS_CROSS_WIN += -fPIC CFLAGS_CROSS_WIN += -I$(WIN_ICONV)/include/ CFLAGS_CROSS_WIN += -DWITH_HWMON -CFLAGS_CROSS_WIN += -D__USE_MINGW_ANSI_STDIO=0 LFLAGS_CROSS_LINUX := $(LFLAGS) LFLAGS_CROSS_LINUX += -lpthread diff --git a/src/event.c b/src/event.c index ec3f3569f..d8ce7a44d 100644 --- a/src/event.c +++ b/src/event.c @@ -8,6 +8,10 @@ #include "thread.h" #include "event.h" +#ifndef __MINGW_PRINTF_FORMAT +#define __MINGW_PRINTF_FORMAT printf +#endif + void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) { event_ctx_t *event_ctx = hashcat_ctx->event_ctx; @@ -62,7 +66,7 @@ void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, cons } } -__attribute__ ((format (printf, 1, 0))) +__attribute__ ((format (__MINGW_PRINTF_FORMAT, 1, 0))) static int event_log (const char *fmt, va_list ap, char *s, const size_t sz) { size_t length;