From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 4 07:30:16 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D3C9B37B512 for ; Fri, 4 Jul 2003 07:30:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 085A244020 for ; Fri, 4 Jul 2003 07:30:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h64EUFUp057449 for ; Fri, 4 Jul 2003 07:30:15 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h64EUFEl057448; Fri, 4 Jul 2003 07:30:15 -0700 (PDT) Resent-Date: Fri, 4 Jul 2003 07:30:15 -0700 (PDT) Resent-Message-Id: <200307041430.h64EUFEl057448@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stefan Farfeleder 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: stefan@fafoe.narf.at Subject: kern/54094: [patch] make signedness of kg_nice and ki_nice explicit X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Stefan Farfeleder List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jul 2003 14:30:17 -0000 >Number: 54094 >Category: kern >Synopsis: [patch] make signedness of kg_nice and ki_nice explicit >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 04 07:30:15 PDT 2003 >Closed-Date: >Last-Modified: >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: >Unformatted: