From stefan@fafoe.dyndns.org Fri Jul 4 07:29:57 2003 Return-Path: Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4EB4C37B401 for ; Fri, 4 Jul 2003 07:29:57 -0700 (PDT) Received: from fafoe.narf.at (chello212186121237.14.vie.surfer.at [212.186.121.237]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B2F244001 for ; Fri, 4 Jul 2003 07:29:56 -0700 (PDT) (envelope-from stefan@fafoe.dyndns.org) Received: from frog.fafoe.narf.at (frog.fafoe.narf.at [192.168.2.101]) by fafoe.narf.at (Postfix) with ESMTP id 9F6793FAA; Fri, 4 Jul 2003 16:29:46 +0200 (CEST) Received: by frog.fafoe.narf.at (Postfix, from userid 1001) id D40EC809; Fri, 4 Jul 2003 16:29:39 +0200 (CEST) Message-Id: <20030704142939.D40EC809@frog.fafoe.narf.at> Date: Fri, 4 Jul 2003 16:29:39 +0200 (CEST) From: Stefan Farfeleder Reply-To: Stefan Farfeleder To: FreeBSD-gnats-submit@freebsd.org Cc: stefan@fafoe.narf.at Subject: [patch] make signedness of kg_nice and ki_nice explicit X-Send-Pr-Version: 3.113 X-GNATS-Notify: >Number: 54094 >Category: kern >Synopsis: [patch] make signedness of kg_nice and ki_nice explicit >Confidential: no >Severity: non-critical >Priority: low >Responsible: grehan >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 04 07:30:15 PDT 2003 >Closed-Date: Thu Jan 22 20:51:15 PST 2004 >Last-Modified: Thu Jan 22 20:51:15 PST 2004 >Originator: Stefan Farfeleder >Release: FreeBSD 5.1-CURRENT i386 >Organization: >Environment: System: FreeBSD frog.fafoe.narf.at 5.1-CURRENT FreeBSD 5.1-CURRENT #19: Fri Jul 4 14:44:41 CEST 2003 freebsd@frog.fafoe.narf.at:/freebsd/frog/obj/freebsd/frog/src/sys/FROG i386 >Description: The members kg_nice of struct ksegrp and ki_nice of struct kinfo_proc hold nice values which can be negative. The C language doesn't specify whether plain char is signed or unsigned, both choices are allowed. Thus using char to store negative values is a bad idea. FreeBSD/PowerPC currently cannot use unsigned char for char because of bugs like this. >How-To-Repeat: >Fix: Originally I wanted to use signed char for k{g,i}_nice but tjr@ suggested using int8_t. --- nice.diff begins here --- Index: src/bin/ps/keyword.c =================================================================== RCS file: /usr/home/ncvs/src/bin/ps/keyword.c,v retrieving revision 1.63 diff -u -r1.63 keyword.c --- src/bin/ps/keyword.c 12 Apr 2003 10:39:56 -0000 1.63 +++ src/bin/ps/keyword.c 4 Jul 2003 11:37:16 -0000 @@ -116,7 +116,7 @@ LONG, "ld", 0}, {"mwchan", "MWCHAN", NULL, LJUST, mwchan, NULL, 6, 0, CHAR, NULL, 0}, {"ni", "", "nice", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d", + {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), INT8_T, "d", 0}, {"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), LONG, "ld", 0}, Index: src/bin/ps/print.c =================================================================== RCS file: /usr/home/ncvs/src/bin/ps/print.c,v retrieving revision 1.82 diff -u -r1.82 print.c --- src/bin/ps/print.c 15 Apr 2003 18:49:20 -0000 1.82 +++ src/bin/ps/print.c 4 Jul 2003 11:33:33 -0000 @@ -690,6 +690,9 @@ case UCHAR: (void)printf(ofmt, v->width, *(u_char *)bp); break; + case INT8_T: + (void)printf(ofmt, v->width, *(int8_t *)bp); + break; case SHORT: (void)printf(ofmt, v->width, *(short *)bp); break; Index: src/bin/ps/ps.h =================================================================== RCS file: /usr/home/ncvs/src/bin/ps/ps.h,v retrieving revision 1.16 diff -u -r1.16 ps.h --- src/bin/ps/ps.h 12 Apr 2003 10:39:56 -0000 1.16 +++ src/bin/ps/ps.h 4 Jul 2003 11:34:01 -0000 @@ -35,7 +35,8 @@ */ #define UNLIMITED 0 /* unlimited terminal width */ -enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, PGTOK }; +enum type { CHAR, UCHAR, INT8_T, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, + PGTOK }; typedef struct kinfo { struct kinfo_proc *ki_p; /* kinfo_proc structure */ Index: src/sys/sys/proc.h =================================================================== RCS file: /usr/home/ncvs/src/sys/sys/proc.h,v retrieving revision 1.339 diff -u -r1.339 proc.h --- src/sys/sys/proc.h 28 Jun 2003 08:29:04 -0000 1.339 +++ src/sys/sys/proc.h 4 Jul 2003 10:53:48 -0000 @@ -498,7 +498,7 @@ #define kg_startcopy kg_endzero u_char kg_pri_class; /* (j) Scheduling class. */ u_char kg_user_pri; /* (j) User pri from estcpu and nice. */ - char kg_nice; /* (c + j) Process "nice" value. */ + int8_t kg_nice; /* (c + j) Process "nice" value. */ #define kg_endcopy kg_numthreads int kg_numthreads; /* (j) Num threads in total */ int kg_kses; /* (j) Num KSEs in group. */ Index: src/sys/sys/user.h =================================================================== RCS file: /usr/home/ncvs/src/sys/sys/user.h,v retrieving revision 1.53 diff -u -r1.53 user.h --- src/sys/sys/user.h 13 May 2003 20:36:02 -0000 1.53 +++ src/sys/sys/user.h 4 Jul 2003 10:55:29 -0000 @@ -143,7 +143,7 @@ long ki_kiflag; /* KI_* flags (below) */ int ki_traceflag; /* Kernel trace points */ char ki_stat; /* S* process status */ - char ki_nice; /* Process "nice" value */ + int8_t ki_nice; /* Process "nice" value */ char ki_lock; /* Process lock (prevent swap) count */ char ki_rqindex; /* Run queue index */ u_char ki_oncpu; /* Which cpu we are on */ --- nice.diff ends here --- >Release-Note: >Audit-Trail: State-Changed-From-To: open->closed State-Changed-By: grehan State-Changed-When: Thu Jan 22 20:49:59 PST 2004 State-Changed-Why: Fix committed Jan 22 04. Slightly simplified: just used "signed char" instead of int8_t, and restricted changes to and Responsible-Changed-From-To: freebsd-bugs->grehan Responsible-Changed-By: grehan Responsible-Changed-When: Thu Jan 22 20:49:59 PST 2004 Responsible-Changed-Why: Fix committed Jan 22 04. Slightly simplified: just used "signed char" instead of int8_t, and restricted changes to and http://www.freebsd.org/cgi/query-pr.cgi?pr=54094 >Unformatted: