From 070eb30ca675029e79f93333b60287527efc0906 Mon Sep 17 00:00:00 2001 From: bde Date: Sat, 31 Aug 1996 16:52:44 +0000 Subject: Fixed the easy cases of const poisoning in the kernel. Cosmetic. --- lib/libc/string/strcmp.c | 2 +- lib/libc/string/strncmp.c | 3 ++- sys/fs/procfs/procfs_subr.c | 4 ++-- sys/kern/imgact_aout.c | 4 ++-- sys/kern/imgact_elf.c | 14 +++++++------- sys/kern/imgact_gzip.c | 4 ++-- sys/kern/imgact_shell.c | 4 ++-- sys/kern/subr_prf.c | 6 +++--- sys/kern/tty.c | 6 +++--- sys/libkern/scanc.c | 8 ++++---- sys/libkern/strcmp.c | 4 ++-- sys/libkern/strncmp.c | 5 +++-- sys/miscfs/procfs/procfs_subr.c | 4 ++-- sys/sys/libkern.h | 4 ++-- 14 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c index 79cfaa8..cf25e50 100644 --- a/lib/libc/string/strcmp.c +++ b/lib/libc/string/strcmp.c @@ -51,5 +51,5 @@ strcmp(s1, s2) while (*s1 == *s2++) if (*s1++ == 0) return (0); - return (*(unsigned char *)s1 - *(unsigned char *)--s2); + return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); } diff --git a/lib/libc/string/strncmp.c b/lib/libc/string/strncmp.c index 805b5b0..4b701a9 100644 --- a/lib/libc/string/strncmp.c +++ b/lib/libc/string/strncmp.c @@ -48,7 +48,8 @@ strncmp(s1, s2, n) return (0); do { if (*s1 != *s2++) - return (*(unsigned char *)s1 - *(unsigned char *)--s2); + return (*(const unsigned char *)s1 - + *(const unsigned char *)(s2 - 1)); if (*s1++ == 0) break; } while (--n != 0); diff --git a/sys/fs/procfs/procfs_subr.c b/sys/fs/procfs/procfs_subr.c index 7d0de04..019a074 100644 --- a/sys/fs/procfs/procfs_subr.c +++ b/sys/fs/procfs/procfs_subr.c @@ -36,7 +36,7 @@ * * @(#)procfs_subr.c 8.4 (Berkeley) 1/27/94 * - * $Id: procfs_subr.c,v 1.8 1996/06/18 05:15:59 dyson Exp $ + * $Id: procfs_subr.c,v 1.9 1996/07/02 13:38:10 dyson Exp $ */ #include @@ -340,7 +340,7 @@ vfs_findname(nm, buf, buflen) int buflen; { for (; nm->nm_name; nm++) - if (bcmp(buf, (char *) nm->nm_name, buflen+1) == 0) + if (bcmp(buf, nm->nm_name, buflen+1) == 0) return (nm); return (0); diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c index 0455da5..3c9d9a8 100644 --- a/sys/kern/imgact_aout.c +++ b/sys/kern/imgact_aout.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: imgact_aout.c,v 1.27 1996/05/01 02:42:41 bde Exp $ + * $Id: imgact_aout.c,v 1.28 1996/05/02 10:43:16 phk Exp $ */ #include @@ -52,7 +52,7 @@ static int exec_aout_imgact(imgp) struct image_params *imgp; { - struct exec *a_out = (struct exec *) imgp->image_header; + const struct exec *a_out = (const struct exec *) imgp->image_header; struct vmspace *vmspace = imgp->proc->p_vmspace; vm_offset_t vmaddr; unsigned long virtual_offset; diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index b44792d..0b96037 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -26,7 +26,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: imgact_elf.c,v 1.6 1996/06/12 05:07:25 gpalmer Exp $ + * $Id: imgact_elf.c,v 1.7 1996/06/18 05:15:46 dyson Exp $ */ #include @@ -67,7 +67,7 @@ static int map_pages __P((struct vnode *vp, vm_offset_t offset, vm_offset_t *buf, vm_size_t size)); static void unmap_pages __P((struct vnode *vp, vm_offset_t buf, vm_size_t size)); static int elf_check_permissions __P((struct proc *p, struct vnode *vp)); -static int elf_check_header __P((Elf32_Ehdr *hdr, int type)); +static int elf_check_header __P((const Elf32_Ehdr *hdr, int type)); static int elf_load_section __P((struct vmspace *vmspace, struct vnode *vp, vm_offset_t offset, caddr_t vmaddr, size_t memsz, size_t filsz, vm_prot_t prot)); static int elf_load_file __P((struct proc *p, char *file, u_long *addr, u_long *entry)); static int elf_freebsd_fixup __P((int **stack_base, struct image_params *imgp)); @@ -237,7 +237,7 @@ elf_check_permissions(struct proc *p, struct vnode *vp) } static int -elf_check_header(Elf32_Ehdr *hdr, int type) +elf_check_header(const Elf32_Ehdr *hdr, int type) { if (!(hdr->e_ident[EI_MAG0] == ELFMAG0 && hdr->e_ident[EI_MAG1] == ELFMAG1 && @@ -468,8 +468,8 @@ fail: int exec_elf_imgact(struct image_params *imgp) { - Elf32_Ehdr *hdr = (Elf32_Ehdr *) imgp->image_header; - Elf32_Phdr *phdr, *mapped_phdr = NULL; + const Elf32_Ehdr *hdr = (const Elf32_Ehdr *) imgp->image_header; + const Elf32_Phdr *phdr, *mapped_phdr = NULL; Elf32_Auxargs *elf_auxargs = NULL; struct vmspace *vmspace = imgp->proc->p_vmspace; vm_prot_t prot = 0; @@ -514,8 +514,8 @@ exec_elf_imgact(struct image_params *imgp) */ phdr = mapped_phdr; } else { - phdr = (Elf32_Phdr*) - ((char*)(imgp->image_header)+hdr->e_phoff); + phdr = (const Elf32_Phdr*) + ((const char *)imgp->image_header + hdr->e_phoff); } /* diff --git a/sys/kern/imgact_gzip.c b/sys/kern/imgact_gzip.c index fd981fcb..32498ae 100644 --- a/sys/kern/imgact_gzip.c +++ b/sys/kern/imgact_gzip.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: imgact_gzip.c,v 1.22 1996/05/02 10:43:16 phk Exp $ + * $Id: imgact_gzip.c,v 1.23 1996/08/01 22:00:14 phk Exp $ * * This module handles execution of a.out files which have been run through * "gzip". This saves diskspace, but wastes cpu-cycles and VM. @@ -66,7 +66,7 @@ exec_gzip_imgact(imgp) struct image_params *imgp; { int error, error2 = 0; - u_char *p = (u_char *) imgp->image_header; + const u_char *p = (const u_char *) imgp->image_header; struct imgact_gzip igz; struct inflate infl; struct vmspace *vmspace; diff --git a/sys/kern/imgact_shell.c b/sys/kern/imgact_shell.c index 3d2e8ff..b00c652 100644 --- a/sys/kern/imgact_shell.c +++ b/sys/kern/imgact_shell.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: imgact_shell.c,v 1.10 1995/12/02 16:32:03 bde Exp $ + * $Id: imgact_shell.c,v 1.11 1996/04/08 01:21:58 davidg Exp $ */ #include @@ -58,7 +58,7 @@ exec_shell_imgact(imgp) char *interp; /* a shell script? */ - if (((short *) image_header)[0] != SHELLMAGIC) + if (((const short *) image_header)[0] != SHELLMAGIC) return(-1); /* diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index bd6ff58..10c5770 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 - * $Id: subr_prf.c,v 1.37 1996/05/09 18:58:06 gpalmer Exp $ + * $Id: subr_prf.c,v 1.38 1996/08/19 20:07:07 julian Exp $ */ #include "opt_ddb.h" @@ -390,14 +390,14 @@ kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_lis for (;;) { padc = ' '; width = 0; - while ((ch = *(u_char *)fmt++) != '%') { + while ((ch = (u_char)*fmt++) != '%') { if (ch == '\0') return retval; PCHAR(ch); } lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; sign = 0; dot = 0; dwidth = 0; -reswitch: switch (ch = *(u_char *)fmt++) { +reswitch: switch (ch = (u_char)*fmt++) { case '.': dot = 1; goto reswitch; diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 4d3c983..bdae27a 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)tty.c 8.8 (Berkeley) 1/21/94 - * $Id: tty.c,v 1.82 1996/06/12 05:07:33 gpalmer Exp $ + * $Id: tty.c,v 1.83 1996/08/28 18:45:09 bde Exp $ */ /*- @@ -135,7 +135,7 @@ static int ttywflush __P((struct tty *tp)); #define TB TAB #define VT VTAB -static char const char_type[] = { +static u_char const char_type[] = { E|CC, O|CC, O|CC, E|CC, O|CC, E|CC, E|CC, O|CC, /* nul - bel */ O|BS, E|TB, E|NL, O|CC, E|VT, O|CR, O|CC, E|CC, /* bs - si */ O|CC, E|CC, E|CC, O|CC, E|CC, O|CC, O|CC, E|CC, /* dle - etb */ @@ -1816,7 +1816,7 @@ loop: ce = cc; else { ce = cc - scanc((u_int)cc, (u_char *)cp, - (u_char *)char_type, CCLASSMASK); + char_type, CCLASSMASK); /* * If ce is zero, then we're processing * a special character through ttyoutput. diff --git a/sys/libkern/scanc.c b/sys/libkern/scanc.c index 7bc3fa0..496b46d 100644 --- a/sys/libkern/scanc.c +++ b/sys/libkern/scanc.c @@ -32,7 +32,7 @@ * * @(#)scanc.c 8.1 (Berkeley) 6/10/93 * - * $Id: scanc.c,v 1.3 1995/03/17 06:15:39 phk Exp $ + * $Id: scanc.c,v 1.4 1995/07/11 18:50:47 bde Exp $ */ #include @@ -40,10 +40,10 @@ int scanc(size, cp, table, mask0) u_int size; - register u_char *cp, table[]; + register const u_char *cp, table[]; int mask0; { - register u_char *end; + register const u_char *end; register u_char mask; mask = mask0; @@ -53,7 +53,7 @@ scanc(size, cp, table, mask0) * The cast to volatile should have no effect, but in fact it * improves the code on i386's. */ - if (table[*(volatile u_char *)cp] & mask) + if (table[*(volatile const u_char *)cp] & mask) break; } return (end - cp); diff --git a/sys/libkern/strcmp.c b/sys/libkern/strcmp.c index c9c397b..48e5635 100644 --- a/sys/libkern/strcmp.c +++ b/sys/libkern/strcmp.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: strcmp.c,v 1.2 1994/08/02 07:44:33 davidg Exp $ */ #include @@ -49,5 +49,5 @@ strcmp(s1, s2) while (*s1 == *s2++) if (*s1++ == 0) return (0); - return (*(unsigned char *)s1 - *(unsigned char *)--s2); + return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); } diff --git a/sys/libkern/strncmp.c b/sys/libkern/strncmp.c index f209e54..e3c4327 100644 --- a/sys/libkern/strncmp.c +++ b/sys/libkern/strncmp.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: strncmp.c,v 1.2 1996/08/28 20:32:21 bde Exp $ */ #include @@ -46,7 +46,8 @@ strncmp(s1, s2, n) return (0); do { if (*s1 != *s2++) - return (*(unsigned char *)s1 - *(unsigned char *)--s2); + return (*(const unsigned char *)s1 - + *(const unsigned char *)(s2 - 1)); if (*s1++ == 0) break; } while (--n != 0); diff --git a/sys/miscfs/procfs/procfs_subr.c b/sys/miscfs/procfs/procfs_subr.c index 7d0de04..019a074 100644 --- a/sys/miscfs/procfs/procfs_subr.c +++ b/sys/miscfs/procfs/procfs_subr.c @@ -36,7 +36,7 @@ * * @(#)procfs_subr.c 8.4 (Berkeley) 1/27/94 * - * $Id: procfs_subr.c,v 1.8 1996/06/18 05:15:59 dyson Exp $ + * $Id: procfs_subr.c,v 1.9 1996/07/02 13:38:10 dyson Exp $ */ #include @@ -340,7 +340,7 @@ vfs_findname(nm, buf, buflen) int buflen; { for (; nm->nm_name; nm++) - if (bcmp(buf, (char *) nm->nm_name, buflen+1) == 0) + if (bcmp(buf, nm->nm_name, buflen+1) == 0) return (nm); return (0); diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h index 7268a1e..c83165e 100644 --- a/sys/sys/libkern.h +++ b/sys/sys/libkern.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)libkern.h 8.1 (Berkeley) 6/10/93 - * $Id: libkern.h,v 1.11 1996/06/08 06:32:48 nate Exp $ + * $Id: libkern.h,v 1.12 1996/08/01 20:31:45 wollman Exp $ */ #ifndef _SYS_LIBKERN_H_ @@ -74,7 +74,7 @@ void qsort __P((void *base, size_t nmemb, size_t size, u_long random __P((void)); char *index __P((const char *, int)); char *rindex __P((const char *, int)); -int scanc __P((u_int, u_char *, u_char *, int)); +int scanc __P((u_int, const u_char *, const u_char *, int)); int skpc __P((int, int, char *)); char *strcat __P((char *, const char *)); int strcmp __P((const char *, const char *)); -- cgit v1.1