From ac7290bedd859af35ac785e9ea7c76863b1e4b32 Mon Sep 17 00:00:00 2001 From: Chad Loder Date: Thu, 15 Dec 2005 05:49:50 +0000 Subject: Add a new warning message: conversion of %s return value from '%s' to '%s'. Lint now warns when a function's return value is converted to a smaller (or differently signed) type. These conversions can happen when doing an assignment, when passing a function's return value as an argument to another function, or when initializing a variable. Currently this produces useless warnings on tolower() and toupper() because they return ints but are usually assigned to chars. --- usr.bin/xlint/lint1/err.c | 5 +++-- usr.bin/xlint/lint1/tree.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index ba64269c3eb..a46486bceae 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.15 2005/12/14 22:09:40 kjell Exp $ */ +/* $OpenBSD: err.c,v 1.16 2005/12/15 05:49:48 cloder Exp $ */ /* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: err.c,v 1.15 2005/12/14 22:09:40 kjell Exp $"; +static char rcsid[] = "$OpenBSD: err.c,v 1.16 2005/12/15 05:49:48 cloder Exp $"; #endif /* number of errors found */ @@ -366,6 +366,7 @@ const char *msgs[] = { "right shift of %d-bit quantity by %d bits", /* 310 */ "case ranges are illegal in ANSI C", /* 311 */ "suspicious operator for sizeof: %s", /* 312 */ + "conversion of %s return value from '%s' to '%s'", /* 313 */ }; /* diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index dc8e5aa6313..92a32b3b93f 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.25 2005/12/14 22:09:40 kjell Exp $ */ +/* $OpenBSD: tree.c,v 1.26 2005/12/15 05:49:49 cloder Exp $ */ /* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: tree.c,v 1.25 2005/12/14 22:09:40 kjell Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.26 2005/12/15 05:49:49 cloder Exp $"; #endif #include @@ -1193,6 +1193,15 @@ asgntypok(op_t op, int arg, tnode_t *ln, tnode_t *rn) rst = (rstp = rtp->t_subt)->t_tspec; mp = &modtab[op]; + /* be picky about conversion of function return types */ + if (rn->tn_op == CALL) { + if (size(lt) < size(rt) || + (size(lt) == size(rt) && isutyp(lt) && !isutyp(rt))) { + warning(313, rn->tn_left->tn_left->tn_sym->s_name, + tyname(rn->tn_type), tyname(ln->tn_type)); + } + } + if (isatyp(lt) && isatyp(rt)) return (1); -- cgit v1.2.3