nfs-utils: fix time_t build error on 64-bits platforms
Subsystems (2)
PATCH 1/1 nfs-utils: fix time_t build error on 64-bits platforms
When passing time_t type to "%ld" on 64-bits platforms where time_t is a
'long long' we encouter this build failure:
error: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘time_t’ {aka ‘long long int’} [-Werror=format=]
So let's change "%ld" markers to "%lld" assuming it to be a 64-bits and cast variables to '(long long)' if the type is a time_t.
--- utils/nfsdcltrack/nfsdcltrack.c | 2 +- utils/nfsdcltrack/sqlite.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
utils/nfsdcltrack/nfsdcltrack.c +1 -1
@@ -525,7 +525,7 @@ cltrack_gracedone(const char *timestr)if (*tail)return -EINVAL ; -xlog (D_GENERAL ,"%s: grace done. gracetime=%ld" , __func__, gracetime); +xlog (D_GENERAL ,"%s: grace done. gracetime=%lld" , __func__, (long long )gracetime); ret =sqlite_remove_unreclaimed (gracetime);
utils/nfsdcltrack/sqlite.c +2 -2
@@ -544,8 +544,8 @@ sqlite_remove_unreclaimed(time_t grace_start)int ret;char *err =NULL ; - ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %ld" , - grace_start); + ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %lld" , + (long long )grace_start);if (ret <0 ) {return ret; }else if ((size_t )ret >=sizeof (buf)) {
Signature · 1 line
2.25.1
Hello,
Quoted 6 lines · Giulio Benetti
When passing
time_ttype to "%ld" on 64-bits platforms wheretime_tis a
'long long' we encouter this build failure:
error: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘time_t’ {aka ‘long long int’} [-Werror=format=]So let's change "%ld" markers to "%lld" assuming it to be a 64-bits and cast variables to '(long long)' if the type is a
time_t.
Just an FYI... I will be using Petr's patches [1] and [2] since they used the inittypes defines which seem a bit more portable and they do the same thing.
steved.
[1] https://marc.info/?l=linux-nfs&m=162697054816925&w=2
[2] https://marc.info/?l=linux-nfs&m=162697054816926&w=2
Quoted 36 lines
Signed-off-by Giulio Benetti <[email protected]>--- utils/nfsdcltrack/nfsdcltrack.c | 2 +- utils/nfsdcltrack/sqlite.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)utils/nfsdcltrack/nfsdcltrack.c +1
-1@@ -525,7 +525,7 @@ cltrack_gracedone(const char *timestr)if (*tail)return -EINVAL ; -xlog (D_GENERAL ,"%s: grace done. gracetime=%ld" , __func__, gracetime); +xlog (D_GENERAL ,"%s: grace done. gracetime=%lld" , __func__, (long long )gracetime); ret =sqlite_remove_unreclaimed (gracetime);utils/nfsdcltrack/sqlite.c +2
-2@@ -544,8 +544,8 @@ sqlite_remove_unreclaimed(time_t grace_start)int ret;char *err =NULL ; - ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %ld" , - grace_start); + ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %lld" , + (long long )grace_start);if (ret <0 ) {return ret; }else if ((size_t )ret >=sizeof (buf)) {
Hello Steve,
Quoted 10 lines
Il giorno 25 lug 2021, alle ore 19:05, Steve Dickson <[email protected]> ha scritto:
Hello,
Quoted 6 lines · Giulio Benetti
When passing
time_ttype to "%ld" on 64-bits platforms wheretime_tis a
'long long' we encouter this build failure:
error: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘time_t’ {aka ‘long long int’} [-Werror=format=] So let's change "%ld" markers to "%lld" assuming it to be a 64-bits and
cast variables to '(long long)' if the type is atime_t.
Quoted 3 lines
Just an FYI... I will be using Petr's patches [1] and [2] since they used the inittypes defines which seem a bit more portable and they do the same thing.
Sure, I’ve missed those patches, thank you for pointing so I can use them in Buildroot instead of this one.
Best regards
Giulio Benetti
Quoted 35 lines
steved.
[1] https://marc.info/?l=linux-nfs&m=162697054816925&w=2
[2] https://marc.info/?l=linux-nfs&m=162697054816926&w=2Quoted 29 lines
Signed-off-by Giulio Benetti <[email protected]>--- utils/nfsdcltrack/nfsdcltrack.c | 2 +- utils/nfsdcltrack/sqlite.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)utils/nfsdcltrack/nfsdcltrack.c +1
-0@@ -525,7 +525,7 @@ cltrack_gracedone(const char *timestr)if (*tail)return -EINVAL ; -xlog (D_GENERAL ,"%s: grace done. gracetime=%ld" , __func__, gracetime); +xlog (D_GENERAL ,"%s: grace done. gracetime=%lld" , __func__, (long long )gracetime); ret =sqlite_remove_unreclaimed (gracetime); diff --git a/utils/nfsdcltrack/sqlite.c b/utils/nfsdcltrack/sqlite.cindex
f79aebb3..6e603087100644utils/nfsdcltrack/sqlite.c +2
-1@@ -544,8 +544,8 @@ sqlite_remove_unreclaimed(time_t grace_start)int ret;char *err =NULL ; - ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %ld" , - grace_start); + ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %lld" , + (long long)grace_start);if (ret <0 ) {return ret; }else if ((size_t )ret >=sizeof (buf)) {