tsto / notmuchfs

A virtual maildir file system for notmuch queries
Other
89 stars 11 forks source link

Cannot compile: comparison of integers of different signs #14

Closed casouri closed 6 years ago

casouri commented 6 years ago

When I try to compile wiht make:

cc -g -O2 -std=c99 -Wall -Wextra -Werror -D_FILE_OFFSET_BITS=64   -c -MD -o notmuchfs.o notmuchfs.c
notmuchfs.c:926:27: error: comparison of integers of different signs: 'long long' and 'size_t'
      (aka 'unsigned long') [-Werror,-Wsign-compare]
   size_t bytes_to_copy = MIN(MAX_XLABEL_LENGTH - offset, size);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/param.h:215:23: note:
      expanded from macro 'MIN'
#define MIN(a,b) (((a)<(b))?(a):(b))
                    ~ ^ ~
1 error generated.
make: *** [notmuchfs.o] Error 1

My OS:

OS: 64bit Mac OS X 10.14.1 18B45d
Kernel: x86_64 Darwin 18.2.0
xcode-select version 2354.

And I have osxfuse installed.

tsto commented 6 years ago

I don't have an OSX dev environment, please check that this patch fixes the issue for you:

diff --git a/notmuchfs.c b/notmuchfs.c
index 7d06a57..b629b25 100644
--- a/notmuchfs.c
+++ b/notmuchfs.c
@@ -923,7 +923,7 @@ static int notmuchfs_read (const char *path,
  assert(p_open != NULL);

  if (offset < MAX_XLABEL_LENGTH) {
-   size_t bytes_to_copy = MIN(MAX_XLABEL_LENGTH - offset, size);
+   size_t bytes_to_copy = MIN((size_t)(MAX_XLABEL_LENGTH - offset), size);
    memcpy(buf, p_open->x_label + offset, bytes_to_copy);
    buf += bytes_to_copy;
    offset_adj = offset + bytes_to_copy;
casouri commented 6 years ago

It works, thank you! 😄