s4-torture: fix truncation warnings
authorUri Simchoni <uri@samba.org>
Sun, 19 Nov 2017 17:11:28 +0000 (17:11 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 24 Nov 2017 00:13:15 +0000 (01:13 +0100)
Fix various places where there is potential truncation
while doing time / size calculations.

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/torture/basic/base.c
source4/torture/raw/open.c
source4/torture/raw/qfileinfo.c
source4/torture/raw/qfsinfo.c

index 8e7ae498aef80171434fad4c5c873a86918620cd..314e8f2d131f30ffca87d91ed340bbf0ebcef57e 100644 (file)
@@ -190,7 +190,7 @@ static bool run_attrtest(struct torture_context *tctx,
 
        torture_comment(tctx, "New file time is %s", ctime(&t));
 
-       if (abs(t - time(NULL)) > 60*60*24*10) {
+       if (labs(t - time(NULL)) > 60*60*24*10) {
                torture_result(tctx, TORTURE_FAIL, "ERROR: SMBgetatr bug. time is %s",
                       ctime(&t));
                t = time(NULL);
@@ -289,13 +289,13 @@ static bool run_trans2test(struct torture_context *tctx,
                        torture_comment(tctx, "modify time=%s", ctime(&m_time));
                        torture_comment(tctx, "This system appears to have sticky create times\n");
                }
-               if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
+               if ((labs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
                        torture_comment(tctx, "access time=%s", ctime(&a_time));
                        torture_result(tctx, TORTURE_FAIL, "This system appears to set a midnight access time\n");
                        correct = false;
                }
 
-               if (abs(m_time - t) > 60*60*24*7) {
+               if (labs(m_time - t) > 60*60*24*7) {
                        torture_result(tctx, TORTURE_FAIL, "ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
                        correct = false;
                }
index 44b04acda9a7db34da1a12a39a1cfee48cf9795c..5e8c81c9d073f69c9061755e95b0d07547283fc0 100644 (file)
@@ -95,7 +95,7 @@ static const char *rdwr_string(enum rdwr_mode m)
        CHECK_STATUS(status, NT_STATUS_OK); \
        t1 = t & ~1; \
        t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
-       if (abs(t1-t2) > 2) { \
+       if (labs(t1-t2) > 2) { \
                torture_result(tctx, TORTURE_FAIL, \
                       "(%s) wrong time for field %s  %s - %s\n", \
                       __location__, #field, \
index 3b89189aa5f2cd131f4fbf0c646dea819705cb86..0c5daa3ccc30f8a09ade29ea8a1bb0d536387d02 100644 (file)
@@ -140,7 +140,7 @@ static struct {
 static int dos_nt_time_cmp(time_t t, NTTIME nt)
 {
        time_t t2 = nt_time_to_unix(nt);
-       if (abs(t2 - t) <= 2) return 0;
+       if (labs(t2 - t) <= 2) return 0;
        return t2 > t ? 1 : -1;
 }
 
index 259aee0e0ec6831e12327456d1b2c465c788f264..0f1717b9cb285d7438b9cf8944ef944be6ae45b2 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include <math.h>
 #include "libcli/libcli.h"
 #include "torture/util.h"
 #include "torture/basic/proto.h"
@@ -206,7 +207,7 @@ bool torture_raw_qfsinfo(struct torture_context *torture,
                        s2->allocation.out.sectors_per_unit *
                        s2->allocation.out.total_alloc_units *
                        s2->allocation.out.bytes_per_sector / scale;
-               if (abs(size1 - size2) > 1) {
+               if (fabs(size1 - size2) > 1) {
                        printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
                               size1, size2);
                        ret = false;
@@ -228,7 +229,7 @@ bool torture_raw_qfsinfo(struct torture_context *torture,
                        s2->allocation.out.sectors_per_unit *
                        s2->allocation.out.avail_alloc_units *
                        s2->allocation.out.bytes_per_sector / scale;
-               if (abs(size1 - size2) > 1) {
+               if (fabs(size1 - size2) > 1) {
                        printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
                               size1, size2);
                        ret = false;