{"thread":{"id":"29525","subject":"[PATCH v2] vcs-svn: Fix some compiler warnings","startedAt":"2012-02-02T18:36:26Z","lastAt":"2012-02-02T18:36:26Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"183625","messageId":"4F2AD7AA.9090904@ramsay1.demon.co.uk","threadId":"29525","inReplyTo":null,"subject":"[PATCH v2] vcs-svn: Fix some compiler warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2012-02-02T18:36:26Z","receivedAt":"2012-02-02T18:36:26Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIn particular, some versions of gcc complains as follows:\n\n        CC vcs-svn/sliding_window.o\n    vcs-svn/sliding_window.c: In function `check_overflow':\n    vcs-svn/sliding_window.c:36: warning: comparison is always false \\\n        due to limited range of data type\n\n        CC vcs-svn/fast_export.o\n    vcs-svn/fast_export.c: In function `fast_export_blob_delta':\n    vcs-svn/fast_export.c:303: warning: comparison is always false due \\\n        to limited range of data type\n\nSimply casting the (limited range unsigned) variable in the comparison\nto an uintmax_t does not suppress the warning, however, since gcc is\n\"smart\" enough to know that the cast does not change anything regarding\nthe value of the casted expression. In order to suppress the warning, we\nintroduce a static inline function to hide the (implicit) cast of the\noriginal variable to an uintmax_t type prior to using it in the overflow\ncheck comparison expression.\n\nNote that the \"some versions of gcc\" which complain includes 3.4.4 and\n4.1.2, whereas gcc version 4.4.0 compiles the code without complaint.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi Jonathan,\n\nAny suggestions for a better name than \"value_too_large_for_off_t\" will\nbe greatly accepted! :)\n\nAlso, I suppose you could make a similar change to the other two sites\nin vcs-svn with similar range checks (fast_export.c:174 and svndiff.c:150).\n\nATB,\nRamsay Jones\n\n git-compat-util.h        |    5 +++++\n vcs-svn/fast_export.c    |    2 +-\n vcs-svn/sliding_window.c |    2 +-\n 3 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 8f3972c..6a6a25a 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -450,6 +450,11 @@ static inline size_t xsize_t(off_t len)\n \treturn (size_t)len;\n }\n \n+static inline int value_too_large_for_off_t(uintmax_t val)\n+{\n+\treturn val > maximum_signed_value_of_type(off_t);\n+}\n+\n static inline int has_extension(const char *filename, const char *ext)\n {\n \tsize_t len = strlen(filename);\ndiff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c\nindex 19d7c34..2e0dcb0 100644\n--- a/vcs-svn/fast_export.c\n+++ b/vcs-svn/fast_export.c\n@@ -300,7 +300,7 @@ void fast_export_blob_delta(uint32_t mode,\n \t\t\t\tuint32_t len, struct line_buffer *input)\n {\n \tlong postimage_len;\n-\tif (len > maximum_signed_value_of_type(off_t))\n+\tif (value_too_large_for_off_t(len))\n \t\tdie(\"enormous delta\");\n \tpostimage_len = apply_delta((off_t) len, input, old_data, old_mode);\n \tif (mode == REPO_MODE_LNK) {\ndiff --git a/vcs-svn/sliding_window.c b/vcs-svn/sliding_window.c\nindex 1bac7a4..0d38482 100644\n--- a/vcs-svn/sliding_window.c\n+++ b/vcs-svn/sliding_window.c\n@@ -33,7 +33,7 @@ static int read_to_fill_or_whine(struct line_buffer *file,\n \n static int check_overflow(off_t a, size_t b)\n {\n-\tif (b > maximum_signed_value_of_type(off_t))\n+\tif (value_too_large_for_off_t(b))\n \t\treturn error(\"unrepresentable length in delta: \"\n \t\t\t\t\"%\"PRIuMAX\" > OFF_MAX\", (uintmax_t) b);\n \tif (signed_add_overflows(a, (off_t) b))\n-- \n1.7.9\n"}]}