Skip to content

Commit cb2f962

Browse files
cebtenzzreintelfx
authored andcommitted
-Werror, more warnings, and warning fixes
1 parent b0111b9 commit cb2f962

15 files changed

Lines changed: 100 additions & 39 deletions

SConstruct

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ def check_sysmacro_h(context):
127127
return rc
128128

129129

130+
def check_stdnoreturn_h(context):
131+
rc = 1
132+
if rc and tests.CheckHeader(context, 'stdnoreturn.h'):
133+
rc = 0
134+
135+
conf.env['HAVE_STDNORETURN_H'] = rc
136+
context.did_show_result = True
137+
context.Result(rc)
138+
return rc
139+
140+
130141
def check_libelf(context):
131142
rc = 1
132143

@@ -618,7 +629,8 @@ conf = Configure(env, custom_tests={
618629
'check_mm_crc32_u64': check_mm_crc32_u64,
619630
'check_cpu_extensions': check_cpu_extensions,
620631
'check_builtin_cpu_supports': check_builtin_cpu_supports,
621-
'check_sysmacro_h': check_sysmacro_h
632+
'check_sysmacro_h': check_sysmacro_h,
633+
'check_stdnoreturn_h': check_stdnoreturn_h
622634
})
623635

624636
#######################################################################
@@ -706,20 +718,33 @@ conf.check_mm_crc32_u64()
706718
if any(cc in os.path.basename(conf.env['CC']) for cc in ('clang', 'include-what-you-use')):
707719
conf.env.Append(CCFLAGS=['-fcolor-diagnostics']) # Colored warnings
708720
conf.env.Append(CCFLAGS=['-Qunused-arguments']) # Hide wrong messages
709-
conf.env.Append(CCFLAGS=['-Wno-bad-function-cast'])
721+
conf.env.Append(CCFLAGS=[
722+
'-Wmost',
723+
'-Wunreachable-code-aggressive',
724+
'-Wno-bad-function-cast',
725+
])
710726
else:
711727
gcc_version = conf.check_gcc_version()
728+
if gcc_version:
729+
conf.env.Append(CCFLAGS=[
730+
'-Wduplicated-cond',
731+
'-Wduplicated-branches',
732+
'-Wlogical-op',
733+
])
712734
if gcc_version >= 8:
713735
conf.env.Append(CCFLAGS=['-Wno-cast-function-type'])
714736

715737
# Optional flags:
716738
conf.env.Append(CCFLAGS=[
717-
'-Wall', '-W', '-Wextra',
739+
'-Wall', '-Wextra',
718740
'-Winit-self',
719-
'-Wstrict-aliasing',
720741
'-Wmissing-include-dirs',
721742
'-Wuninitialized',
722743
'-Wstrict-prototypes',
744+
'-Wnull-dereference',
745+
'-Wformat-security',
746+
'-Wformat-y2k',
747+
'-Wmissing-noreturn',
723748
'-Wno-implicit-fallthrough',
724749
])
725750

@@ -745,6 +770,7 @@ conf.check_btrfs_h()
745770
conf.check_linux_fs_h()
746771
conf.check_uname()
747772
conf.check_sysmacro_h()
773+
conf.check_stdnoreturn_h()
748774
conf.check_cpu_extensions()
749775

750776
if conf.env['HAVE_LIBELF']:
@@ -763,7 +789,7 @@ if conf.env['HAVE_SSE2']:
763789
conf.env.Append(CCFLAGS=['-msse2'])
764790

765791
# NB: After checks so they don't fail
766-
conf.env.Append(CCFLAGS=['-Werror=undef'])
792+
conf.env.Append(CCFLAGS=['-Werror'])
767793

768794

769795
if ARGUMENTS.get('GDB') == '1':

lib/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def build_config_template(target, source, env):
4242
HAVE_BUILTIN_CPU_SUPPORTS=env['HAVE_BUILTIN_CPU_SUPPORTS'],
4343
HAVE_UNAME=env['HAVE_UNAME'],
4444
HAVE_SYSMACROS_H=env['HAVE_SYSMACROS_H'],
45+
HAVE_STDNORETURN_H=env['HAVE_STDNORETURN_H'],
4546
VERSION_MAJOR=VERSION_MAJOR,
4647
VERSION_MINOR=VERSION_MINOR,
4748
VERSION_PATCH=VERSION_PATCH,

lib/checksum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void rm_digest_glib_steal(GChecksum *state, guint8 *result, gsize *len) {
438438
.free = (RmDigestFreeFunc)g_checksum_free, \
439439
.update = (RmDigestUpdateFunc)g_checksum_update, \
440440
.copy = (RmDigestCopyFunc)g_checksum_copy, \
441-
.steal = (RmDigestStealFunc)rm_digest_##NAME##_steal};
441+
.steal = (RmDigestStealFunc)rm_digest_##NAME##_steal}
442442

443443
/* md5 */
444444
static GChecksum *rm_digest_md5_new(void) {
@@ -587,7 +587,7 @@ RM_DIGEST_DEFINE_SHA3(512)
587587
.free = (RmDigestFreeFunc)rm_digest_##ALGO##_free, \
588588
.update = (RmDigestUpdateFunc)ALGO##_update, \
589589
.copy = (RmDigestCopyFunc)rm_digest_##ALGO##_copy, \
590-
.steal = (RmDigestStealFunc)rm_digest_##ALGO##_steal};
590+
.steal = (RmDigestStealFunc)rm_digest_##ALGO##_steal}
591591

592592
CREATE_BLAKE2_INTERFACE(blake2b, BLAKE2B);
593593
CREATE_BLAKE2_INTERFACE(blake2bp, BLAKE2B);

lib/cmdline.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string.h>
2929
#include <search.h>
3030

31+
#include "config.h"
3132
#include "formats.h"
3233
#include "md-scheduler.h"
3334
#include "preprocess.h"
@@ -51,7 +52,7 @@ static const RmDigestType RM_PARANOIA_LEVELS[] = {RM_DIGEST_METRO,
5152
static const int RM_PARANOIA_NORMAL = 3; /* must be index of RM_DEFAULT_DIGEST */
5253
static const int RM_PARANOIA_MAX = 5;
5354

54-
static void rm_cmd_show_version(void) {
55+
NORETURN static void rm_cmd_show_version(void) {
5556
fprintf(stderr, "version %s compiled: %s at [%s] \"%s\" (rev %s)\n", RM_VERSION,
5657
__DATE__, __TIME__, RM_VERSION_NAME, RM_VERSION_GIT_REVISION);
5758

@@ -86,20 +87,20 @@ static void rm_cmd_show_version(void) {
8687
exit(0);
8788
}
8889

89-
static void rm_cmd_show_manpage(void) {
90-
static const char *commands[] = {"man %s docs/_build/man/rmlint.1 2> /dev/null",
91-
"man %s rmlint", NULL};
90+
#if RM_MANPAGE_USE_PAGER
91+
#define MAN_OPTS ""
92+
#else
93+
#define MAN_OPTS "-P cat"
94+
#endif
95+
96+
NORETURN static void rm_cmd_show_manpage(void) {
97+
static const char *commands[] = {"man " MAN_OPTS " docs/_build/man/rmlint.1.gz 2> /dev/null",
98+
"man " MAN_OPTS " rmlint", NULL};
9299

93100
bool found_manpage = false;
94101

95102
for(int i = 0; commands[i] && !found_manpage; ++i) {
96-
char cmd_buf[512] = {0};
97-
if(snprintf(cmd_buf, sizeof(cmd_buf), commands[i],
98-
(RM_MANPAGE_USE_PAGER) ? "" : "-P cat") == -1) {
99-
continue;
100-
}
101-
102-
if(system(cmd_buf) == 0) {
103+
if(system(commands[i]) == 0) {
103104
found_manpage = true;
104105
}
105106
}

lib/config.h.in

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define HAVE_LINUX_FS_H ({HAVE_LINUX_FS_H})
2222
#define HAVE_UNAME ({HAVE_UNAME})
2323
#define HAVE_SYSMACROS_H ({HAVE_SYSMACROS_H})
24+
#define HAVE_STDNORETURN_H ({HAVE_STDNORETURN_H})
2425
#define HAVE_MM_CRC32_U64 ({HAVE_MM_CRC32_U64})
2526
#define HAVE_BUILTIN_CPU_SUPPORTS ({HAVE_BUILTIN_CPU_SUPPORTS})
2627

@@ -100,7 +101,7 @@ typedef guint64 RmOff;
100101
#endif
101102
#ifdef __GNUC__
102103
#define INLINE inline __attribute__((__always_inline__))
103-
#elif defined(__CLANG__)
104+
#elif defined(__clang__)
104105
#if __has_attribute(__always_inline__)
105106
#define INLINE inline __attribute__((__always_inline__))
106107
#endif
@@ -115,13 +116,27 @@ typedef guint64 RmOff;
115116

116117
#ifdef __GNUC__
117118
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
118-
#elif defined(__CLANG__)
119+
#elif defined(__clang__)
119120
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
120121
#else
121122
/* give up */
122123
#define WARN_UNUSED_RESULT
123124
#endif
124125

126+
#if HAVE_STDNORETURN_H
127+
#include <stdnoreturn.h>
128+
#endif
129+
130+
#ifdef noreturn
131+
#define NORETURN noreturn
132+
#elif defined(__GNUC__) || defined(__clang__)
133+
#define NORETURN __attribute__((__noreturn__))
134+
#elif defined(_MSC_VER)
135+
#define NORETURN __declspec(noreturn)
136+
#else
137+
#define noreturn
138+
#endif
139+
125140
#define _RM_OFFSET_DEBUG 0
126141

127142
#endif

lib/formats/sh.c.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ typedef struct RmFmtHandlerShScript {
4545
RmOff line_count;
4646
} RmFmtHandlerShScript;
4747

48-
static const char *SH_SCRIPT_TEMPLATE_HEAD = "<<SH_SOURCE>>";
49-
static const char *SH_SCRIPT_TEMPLATE_FOOT =
48+
static const char SH_SCRIPT_TEMPLATE_HEAD[] = "<<SH_SOURCE>>";
49+
static const char SH_SCRIPT_TEMPLATE_FOOT[] =
5050
"\n"
5151
"\n"
5252
"\n"

lib/formats/stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static void rm_fmt_prog(RmSession *session,
9696
fprintf(out, _("%s%15ld%s Other lint items\n"), MAYBE_RED(out, session),
9797
(long)session->other_lint_cnt, MAYBE_RESET(out, session));
9898

99-
gfloat elapsed = g_timer_elapsed(session->timer_since_proc_start, NULL);
99+
gdouble elapsed = g_timer_elapsed(session->timer_since_proc_start, NULL);
100100

101101
char *elapsed_time = rm_format_elapsed_time(elapsed, 5);
102102
fprintf(out, _("%s%15s%s of time spent scanning\n"), MAYBE_RED(out, session),

lib/formats/summary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void rm_fmt_prog(RmSession *session,
107107
_("This run was a replay from a previous run. No I/O done!\n"));
108108
}
109109

110-
gfloat elapsed = g_timer_elapsed(session->timer_since_proc_start, NULL);
110+
gdouble elapsed = g_timer_elapsed(session->timer_since_proc_start, NULL);
111111
char *elapsed_time = rm_format_elapsed_time(elapsed, 3);
112112
ARROW fprintf(out, _("Scanning took in total %s%s%s.\n"), MAYBE_RED(out, session),
113113
elapsed_time, MAYBE_RESET(out, session));

lib/pathtricia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct _RmNode {
5353
ino_t inode;
5454

5555
/* data was set explicitly */
56-
char has_value : 1;
56+
bool has_value : 1;
5757

5858
/* User specific data */
5959
gpointer data;

lib/reflink.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ RmLinkType rm_reflink_type_from_fd(int fd1, int fd2) {
167167

168168
return RM_LINK_ERROR;
169169
#else
170+
(void)fd1;
171+
(void)fd2;
170172
return RM_LINK_NONE;
171173
#endif
172174
}
@@ -318,7 +320,7 @@ int rm_dedupe_main(int argc, const char **argv) {
318320
rm_log_warning_line("dedupe: failed to preserve ownership for %s",
319321
source_path);
320322
// try to preserve group ID
321-
(void)lchown(cloneto_path, -1, source_stat.st_gid);
323+
(void)!lchown(cloneto_path, -1, source_stat.st_gid);
322324
}
323325

324326
if(lchmod(cloneto_path, source_stat.st_mode) != 0) {
@@ -510,11 +512,10 @@ int rm_is_reflink_main(int argc, const char **argv) {
510512
g_option_context_free(context);
511513
g_free(summary);
512514

513-
if(!HAVE_FIEMAP) {
514-
rm_log_error_line(_("Cannot test for reflinks because rmlint was compiled without fiemap support"));
515-
return EXIT_FAILURE;
516-
}
517-
515+
#if !HAVE_FIEMAP
516+
rm_log_error_line(_("Cannot test for reflinks because rmlint was compiled without fiemap support"));
517+
return EXIT_FAILURE;
518+
#else
518519
const char *a = argv[1];
519520
const char *b = argv[2];
520521

@@ -535,4 +536,5 @@ int rm_is_reflink_main(int argc, const char **argv) {
535536
rm_log_info("Link type for '%s' and '%s', result:\n", a, b);
536537
rm_log_warning("%s\n", desc[result]);
537538
return result;
539+
#endif
538540
}

0 commit comments

Comments
 (0)