~0 and -1 are the same for two-complement machines. ISO C says left

shifts of negative values are UB, so do the shift for the unsigned
equivalent and cast to int afterwards.
This commit is contained in:
joerg 2015-08-28 09:42:07 +00:00
parent 3030f667e1
commit 0555fac4ac
2 changed files with 7 additions and 7 deletions

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scan.l,v 1.60 2014/10/18 08:33:30 snj Exp $ */
/* $NetBSD: scan.l,v 1.61 2015/08/28 09:42:07 joerg Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: scan.l,v 1.60 2014/10/18 08:33:30 snj Exp $");
__RCSID("$NetBSD: scan.l,v 1.61 2015/08/28 09:42:07 joerg Exp $");
#endif
#include <stdlib.h>
@ -49,7 +49,7 @@ __RCSID("$NetBSD: scan.l,v 1.60 2014/10/18 08:33:30 snj Exp $");
#include "lint1.h"
#include "cgram.h"
#define CHAR_MASK (~(~0 << CHAR_BIT))
#define CHAR_MASK ((int)(~(~0U << CHAR_BIT)))
/* Current position (its also updated when an included file is parsed) */
pos_t curr_pos = { 1, "", 0 };

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.80 2015/07/29 18:23:32 christos Exp $ */
/* $NetBSD: tree.c,v 1.81 2015/08/28 09:42:07 joerg Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.80 2015/07/29 18:23:32 christos Exp $");
__RCSID("$NetBSD: tree.c,v 1.81 2015/08/28 09:42:07 joerg Exp $");
#endif
#include <stdlib.h>
@ -3795,14 +3795,14 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
if ((hflag || pflag) && lt == CHAR && rn->tn_op == CON &&
(rn->tn_val->v_quad < 0 ||
rn->tn_val->v_quad > ~(~0 << (CHAR_BIT - 1)))) {
rn->tn_val->v_quad > (int)~(~0U << (CHAR_BIT - 1)))) {
/* nonportable character comparison, op %s */
warning(230, mp->m_name);
return;
}
if ((hflag || pflag) && rt == CHAR && ln->tn_op == CON &&
(ln->tn_val->v_quad < 0 ||
ln->tn_val->v_quad > ~(~0 << (CHAR_BIT - 1)))) {
ln->tn_val->v_quad > (int)~(~0U << (CHAR_BIT - 1)))) {
/* nonportable character comparison, op %s */
warning(230, mp->m_name);
return;