Skip to content

Commit

Permalink
fix undefined macros
Browse files Browse the repository at this point in the history
The worst of them were an undefined UINTPTR_MAX in RM_PLATFORM_*, which
could both be false and caused a stat struct to be mis-casted in
traverse.c, and a non-macro HASHER_FADVISE_FLAGS that made
rm_hasher_request_readahead a no-op since commit 31cd32f.

Also add a static assert in the usual ADD_FILE to make sure it never
casts between incompatible stat structs, and -Werror=undef so we don't
allow undefined macros to silently evaluate to zero.

Fixes sahib#549
  • Loading branch information
cebtenzzre committed Jan 24, 2022
1 parent bdb591f commit 3579b7f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ if conf.env['HAVE_SSE4_1']:
if conf.env['HAVE_SSE2']:
conf.env.Append(CCFLAGS=['-msse2'])

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


if ARGUMENTS.get('GDB') == '1':
ARGUMENTS['DEBUG'] = '1'
Expand Down
13 changes: 9 additions & 4 deletions lib/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@
#define LLI G_GINT64_FORMAT


#include <stdint.h> /* for UINTPTR_MAX */
#define RM_PLATFORM_32 (UINTPTR_MAX == 0xffffffff)
#define RM_PLATFORM_64 (UINTPTR_MAX == 0xffffffffffffffff)

#ifdef __APPLE__
# ifdef __MACH__
# define RM_IS_APPLE 1
# endif
#if defined(__APPLE__) && defined(__MACH__)
# define RM_IS_APPLE 1
#else
# define RM_IS_APPLE 0
#endif

#ifdef __CYGWIN__
# define RM_IS_CYGWIN 1
#else
# define RM_IS_CYGWIN 0
#endif

#include <glib.h>
Expand Down Expand Up @@ -119,4 +122,6 @@ typedef guint64 RmOff;
#define WARN_UNUSED_RESULT
#endif

#define _RM_OFFSET_DEBUG 0

#endif
25 changes: 14 additions & 11 deletions lib/hasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@

#include "utilities.h"

/* Flags for the fadvise() call that tells the kernel
* what we want to do with the file.
*/
const int HASHER_FADVISE_FLAGS = 0
#ifdef POSIX_FADV_SEQUENTIAL
| POSIX_FADV_SEQUENTIAL /* Read from 0 to file-size */
#ifndef POSIX_FADV_SEQUENTIAL
# define POSIX_FADV_SEQUENTIAL 0
#endif
#ifdef POSIX_FADV_WILLNEED
| POSIX_FADV_WILLNEED /* Tell the kernel to readahead */
#ifndef POSIX_FADV_WILLNEED
# define POSIX_FADV_WILLNEED 0
#endif
#ifdef POSIX_FADV_NOREUSE
| POSIX_FADV_NOREUSE /* We will not reuse old data */
#ifndef POSIX_FADV_NOREUSE
# define POSIX_FADV_NOREUSE 0
#endif
;

/* Flags for the fadvise() call that tells the kernel
* what we want to do with the file.
*/
#define HASHER_FADVISE_FLAGS 0 \
| POSIX_FADV_SEQUENTIAL /* Read from 0 to file-size */ \
| POSIX_FADV_WILLNEED /* Tell the kernel to readahead */ \
| POSIX_FADV_NOREUSE /* We will not reuse old data */

#define DIVIDE_CEIL(n, m) ((n) / (m) + !!((n) % (m)))

Expand Down
2 changes: 2 additions & 0 deletions lib/md-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "md-scheduler.h"


#define _RM_MDS_DEBUG 0

/* How many milliseconds to sleep if we encounter an empty file queue.
* This prevents a "starving" RmShredDevice from hogging cpu and cluttering up
* debug messages by continually recycling back to the joiner.
Expand Down
9 changes: 7 additions & 2 deletions lib/traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,13 @@ static void rm_traverse_convert_small_stat_buf(struct stat *fts_statp, RmStat *b

#else

#define ADD_FILE(lint_type, is_symlink) \
_ADD_FILE(lint_type, is_symlink, (RmStat *)p->fts_statp)
#define ADD_FILE(lint_type, is_symlink) \
{ \
G_STATIC_ASSERT( \
G_SIZEOF_MEMBER(RmStat, st_size) == \
G_SIZEOF_MEMBER(__fts_stat_t, st_size)); \
_ADD_FILE(lint_type, is_symlink, (RmStat *)p->fts_statp) \
}

#endif

Expand Down
2 changes: 0 additions & 2 deletions lib/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,6 @@ bool rm_mounts_can_reflink(RmMountTable *self, dev_t source, dev_t dest) {

#if HAVE_FIEMAP

#define _RM_OFFSET_DEBUG 0

/* Return fiemap structure containing n_extents for file descriptor fd.
* Return NULL if errors encountered.
* Needs to be freed with g_free if not NULL.
Expand Down

0 comments on commit 3579b7f

Please sign in to comment.