Skip to contentSkip to conversation

syscalls/remap_file_pages: unsigned int is always greater to zero

PATCH In review Markos Chandras 4 participants 5 messages Jan 3, 2012 – Jan 5, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 8/21 syscalls/remap_file_pages: unsigned int is always greater to zero

Hi, please review the attached patch

Signature · 1 line
markos

From 91f35a787627ef3bfb77dd0f0dc5e8993016b0b5 Mon Sep 17 00:00:00 2001
From: Markos Chandras <[email protected]>
Date: Thu, 22 Dec 2011 13:05:58 +0000
Subject: [PATCH 08/21] syscalls/remap_file_pages: unsigned int is always greater to zero

getpagesize() returns an integer value ( which can be negative in case of an error ). However, when a negative value is assigned to unsigned int, the result is a much greater integer (2's complement), therefore the expression page_sz > 0 is always true. A getpagesize() error won't be noticed in this case

---
 .../syscalls/remap_file_pages/remap_file_pages01.c |    6 +++---
 .../syscalls/remap_file_pages/remap_file_pages02.c |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/remap_file_pages/remap_file_pages01.c +3 -3
index 01fd291..fa1bdca 100644
@@ -231,11 +231,11 @@ void setup()
 	TEST_PAUSE;
 
 	/* Get page size */
-	if ((page_sz = getpagesize()) < 0) {
+	if (getpagesize() < 0) {
 		tst_brkm(TFAIL, cleanup,
 			 "getpagesize() fails to get system page size");
 	}
-
+	page_sz = getpagesize();
 	page_words = (page_sz / sizeof(char));
 
 	/* Set the cache size */
@@ -287,4 +287,4 @@ void cleanup(char *data)
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
testcases/kernel/syscalls/remap_file_pages/remap_file_pages02.c +2 -2
index c30abe8..c70bfe8 100644
@@ -281,11 +281,11 @@ void setup()
 	tst_tmpdir();
 
 	/* Get page size */
-	if ((page_sz = getpagesize()) < 0) {
+	if (getpagesize() < 0) {
 		tst_brkm(TFAIL, cleanup,
 			 "getpagesize() fails to get system page size");
 	}
-
+	page_sz = getpagesize();
 	page_words = (page_sz / sizeof(char));
 
 	/* Set the cache size */
Signature · 1 line
1.7.1

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reviewed-by on v1 8/21
#1 lore raw
Quoted 1 line · Markos Chandras

Hi, please review the attached patch

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
In reply to Markos Chandras
Quoted 1 line · On Tuesday 03 January 2012 06:04:38 Markos Chandras wrote:

Hi, please review the attached patch

you should add a local int variable, store getpagesize() into that, and then use that to initialize page_sz rather than call getpagesize() multiple times. -mike

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Hi!

Quoted 2 lines

you should add a local int variable, store getpagesize() into that, and then use that to initialize page_sz rather than call getpagesize() multiple times.

That would be better.

And moreover isn't sizeof(char) == 1 by definition?

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi!

Quoted 5 lines
Quoted 1 line

And moreover isn't sizeof(char) == 1 by definition?

i don't know the ISO C spec well enough to say. but it's probably safe to say that sizeof(char) will always be 1 on any system we ever care about. personally i wouldn't discourage the use of sizeof(char) when it makes sense.

Looked that up:

"It's fundamental to correct usage of functions such as malloc and fread
that sizeof(char) be exactly one. In practise, this means that byte in C terms is the smallest unit of storage, even if this unit is 36 bits wide; and all objects are composed of an integer number of these smallest units."

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list