brl: don't use conversion to float for offset and count

Ralph Böhme rb at sernet.de
Sun Jun 1 12:37:18 MDT 2014


Hi

attached is a small fix, that deals with wrong results by printf()
conversion from integer to float when printing lock offsets and
sizes. For large values such a conversion may produce wrong results,
instead use one of the standard conversion specifiers for integers.

Example: The integer

  9223372036854775798 (= 0x7FFFFFFFFFFFFFF6)

is printed as

  9223372036854775808 (= 0x7FFFFFFFFFFFFFFF)

when using a cast to float (double) and a double conversion specifier.

Review appreciated.

Thanks!
-Ralph

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de,mailto:kontakt@sernet.de
-------------- next part --------------
>From 89cdd0f18ae10ab05bd2ba47dd27623a77159c63 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <rb at sernet.de>
Date: Sun, 1 Jun 2014 15:16:16 +0200
Subject: [PATCH] locking: use correct conversion specifier for printing
 variables

Fix several occurences of using printf conversion to fload when
printing offset and count variables in locking debug messages and
smbstatus.

Conversion to float may lead to wrong results with very large values.

Signed-off-by: Ralph Boehme <rb at sernet.de>
---
 source3/locking/locking.c |  4 ++--
 source3/locking/posix.c   | 13 +++++++------
 source3/utils/status.c    |  4 ++--
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 4ef6b89..b3f65ee 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -266,10 +266,10 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 
 	/* NOTE! 0 byte long ranges ARE allowed and should be stored  */
 
-	DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f "
+	DEBUG(10,("do_lock: lock flavour %s lock type %s start=%ju len=%ju "
 		"blocking_lock=%s requested for %s file %s\n",
 		lock_flav_name(lock_flav), lock_type_name(lock_type),
-		(double)offset, (double)count, blocking_lock ? "true" :
+		(uintmax_t)offset, (uintmax_t)count, blocking_lock ? "true" :
 		"false", fsp_fnum_dbg(fsp), fsp_str_dbg(fsp)));
 
 	br_lck = brl_get_locks(talloc_tos(), fsp);
diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index 2d89110..908cd57 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -186,7 +186,8 @@ static bool posix_fcntl_lock(files_struct *fsp, int op, off_t offset, off_t coun
 {
 	bool ret;
 
-	DEBUG(8,("posix_fcntl_lock %d %d %.0f %.0f %d\n",fsp->fh->fd,op,(double)offset,(double)count,type));
+	DEBUG(8,("posix_fcntl_lock %d %d %jd %jd %d\n",
+		 fsp->fh->fd,op,(intmax_t)offset,(intmax_t)count,type));
 
 	ret = SMB_VFS_LOCK(fsp, op, offset, count, type);
 
@@ -1165,9 +1166,9 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
 	off_t count;
 	int posix_lock_type = map_posix_lock_type(fsp,lock_type);
 
-	DEBUG(5,("set_posix_lock_posix_flavour: File %s, offset = %.0f, count "
-		 "= %.0f, type = %s\n", fsp_str_dbg(fsp),
-		 (double)u_offset, (double)u_count,
+	DEBUG(5,("set_posix_lock_posix_flavour: File %s, offset = %ju, count "
+		 "= %ju, type = %s\n", fsp_str_dbg(fsp),
+		 (uintmax_t)u_offset, (uintmax_t)u_count,
 		 posix_lock_type_name(lock_type)));
 
 	/*
@@ -1181,8 +1182,8 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
 
 	if (!posix_fcntl_lock(fsp,F_SETLK,offset,count,posix_lock_type)) {
 		*errno_ret = errno;
-		DEBUG(5,("set_posix_lock_posix_flavour: Lock fail !: Type = %s: offset = %.0f, count = %.0f. Errno = %s\n",
-			posix_lock_type_name(posix_lock_type), (double)offset, (double)count, strerror(errno) ));
+		DEBUG(5,("set_posix_lock_posix_flavour: Lock fail !: Type = %s: offset = %ju, count = %ju. Errno = %s\n",
+			posix_lock_type_name(posix_lock_type), (intmax_t)offset, (intmax_t)count, strerror(errno) ));
 		return False;
 	}
 	return True;
diff --git a/source3/utils/status.c b/source3/utils/status.c
index 61a450e..7bbcea5 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -240,10 +240,10 @@ static void print_brl(struct file_id id,
 		}
 	}
 
-	d_printf("%-10s %-15s %-4s %-9.0f %-9.0f %-24s %-24s\n", 
+	d_printf("%-10s %-15s %-4s %-9jd %-9jd %-24s %-24s\n",
 		 procid_str_static(&pid), file_id_string_tos(&id),
 		 desc,
-		 (double)start, (double)size,
+		 (intmax_t)start, (intmax_t)size,
 		 sharepath, fname);
 
 	TALLOC_FREE(fname);
-- 
1.9.3



More information about the samba-technical mailing list