portability patch for char signedness
The attached patch fixes some char signedness issues. These are a problem on arm and SPARC.
BTW One of my friends is working on the SPARC port of SE Linux, hopefully he'll have something ready for inclusion in the next release of SE Linux. I was planning to do the SPARC port myself, but I ran out of time.
Signature · 4 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page
tmp/selinux-small-2003011510/libsecure/test/msgget_s.c renamed from libsecure/test/msgget_s.c +3 -3
@@ -31,11 +31,11 @@key_t ipc_key;int ret;security_id_t sid =SECSID_NULL ; -char c; +int c_int;int id; -while ( (c =getopt (argc, argv,"k:c:s:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"k:c:s:" )) !=EOF ) { +switch ((char )c_int) {case 'k' : ipc_key =atoi (optarg); valid_ipc_key =1 ;
tmp/selinux-small-2003011510/libsecure/test/msgsnd_s.c renamed from libsecure/test/msgsnd_s.c +3 -3
@@ -42,10 +42,10 @@int valid_msg_sid =0 ;char *word, *first_words;int ret; -char c; +int c_int; -while ( (c =getopt (argc, argv,"c:i:s:t:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"c:i:s:t:" )) !=EOF ) { +switch ((char )c_int) {case 's' :if (valid_msg_sid) {fprintf (stderr,"Only a sid or a context may be given, not both\n" );
tmp/selinux-small-2003011510/libsecure/test/semget_s.c renamed from libsecure/test/semget_s.c +3 -3
@@ -32,11 +32,11 @@key_t ipc_key;int ret;security_id_t sid; -char c; +int c_int;int id; -while ( (c =getopt (argc, argv,"k:c:s:n:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"k:c:s:n:" )) !=EOF ) { +switch ((char )c_int) {case 'k' : ipc_key =atoi (optarg); valid_ipc_key =1 ;
tmp/selinux-small-2003011510/libsecure/test/shmget_s.c renamed from libsecure/test/shmget_s.c +3 -3
@@ -32,11 +32,11 @@key_t ipc_key;int err, ret;security_id_t sid =SECSID_NULL ; -char c; +int c_int;int id; -while ( (c =getopt (argc, argv,"k:c:s:b:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"k:c:s:b:" )) !=EOF ) { +switch ((char )c_int) {case 'k' : ipc_key =atoi (optarg); valid_ipc_key =1 ;
tmp/selinux-small-2003011510/libsecure/test/msgget_s.c line 38
Quoted 9 lines · On Mon, 14 Apr 2003 00:59:54 -0400 Russell Coker <[email protected]> wrote:
The attached patch fixes some char signedness issues.
tmp/selinux-small-2003011510/libsecure/test/msgget_s.c renamed from libsecure/test/msgget_s.c +3
-3-char c; +int c_int; -while ( (c =getopt (argc, argv,"k:c:s:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"k:c:s:" )) !=EOF ) { +switch ((char )c_int) {
A slightly simpler fix is to just change the type of "c" to int without renaming or casting. "getopt" returns an int, all of the case statements are ints, and "c" is not used in any other context.
-Dave Dodge/[email protected]
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 10 lines · Dave Dodge
tmp/selinux-small-2003011510/libsecure/test/msgget_s.c line 38
Quoted 9 lines
The attached patch fixes some char signedness issues.
tmp/selinux-small-2003011510/libsecure/test/msgget_s.c renamed from libsecure/test/msgget_s.c +3
-3-char c; +int c_int; -while ( (c =getopt (argc, argv,"k:c:s:" )) !=EOF ) { -switch (c) { +while ( (c_int =getopt (argc, argv,"k:c:s:" )) !=EOF ) { +switch ((char )c_int) {
Quoted 4 lines
A slightly simpler fix is to just change the type of "c" to int without renaming or casting. "getopt" returns an int, all of the case statements are ints, and "c" is not used in any other context.
True. However single character variable names are often an annoyance to programmers. The traditional variables i, j, and maybe k for loops are generally accepted, but otherwise it's generally considered to be a good idea to have a longer name that can be searched for more easily. With the name c_int you can just type "/c_int" in vi to find the next use of it, while "/c" will return lots of matches that you don't want.
It took me a few extra seconds to review every file I was patching because of this, so I decided that it would be good to change the variable name and save the next programmer the effort.
Signature · 10 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · On Thu, 24 Apr 2003 13:11:25 +1000 Russell Coker <[email protected]> wrote:
Quoted 1 line · Dave Dodge
Quoted 1 line
+ int
c_int;
[...]
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
+ switch ((char)c_int) {
A slightly simpler fix is to just change the type of "c" to int without renaming or casting. "getopt" returns an int, all of the case statements are ints, and "c" is not used in any other context.
[...] it's generally considered to be a good idea to have a longer name that can be searched for more easily.
Good point. In that case perhaps it should be renamed something like "optletter". I'd still leave out the cast to char.
-Dave Dodge/[email protected]
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.