Skip to content

Commit

Permalink
Fix MinGW printf formats
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
neheb committed Dec 9, 2023
1 parent d064d9d commit ae3390e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
22 changes: 13 additions & 9 deletions include/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion include/logfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion include/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define HC_SHARED_H

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand All @@ -24,6 +25,10 @@
#include <sys/select.h>
#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);

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ae3390e

Please sign in to comment.