From patchwork Sat Apr 25 11:11:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Nagy X-Patchwork-Id: 19941 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3PBBOWl012911 for ; Sat, 25 Apr 2009 11:11:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751562AbZDYLLX (ORCPT ); Sat, 25 Apr 2009 07:11:23 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752297AbZDYLLX (ORCPT ); Sat, 25 Apr 2009 07:11:23 -0400 Received: from mail-ew0-f176.google.com ([209.85.219.176]:36125 "EHLO mail-ew0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751562AbZDYLLW (ORCPT ); Sat, 25 Apr 2009 07:11:22 -0400 Received: by ewy24 with SMTP id 24so1392485ewy.37 for ; Sat, 25 Apr 2009 04:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type; bh=WudSQjoazbDFweEL45JhDBOzdeFUqNCn4UnSnkjpVn4=; b=sbmdWy90reuWcxjPOKtG2t3D6BqOHDy5ke9lfu0lYrtEjNLRvOboCeFIEO77EqM2Lq rlHtOAKCZjBHVJbWlAwDwX3u6BUhZ+8foZLtQEqRITtjZa0lUuKF12wSHFJ0jhyrNkae N3C1k1AuQkhEgDPMHZTcMygITp2OkF5S1TehE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type; b=WDHlxBA7sLnmTrpotqbkk29EGHrvByWZIK/mUbWYRxAYmlbQRYP1ZlMGlevao7ovEe A1zEEUcTC1sfJmifOnqf7i/eYlG/g0nA2ysf79QMmPya+ZPczrqCrauoIS6YGQIrHOcf dp18g8suO3dC05FnwyMoBD8P06QhuAyFl5wXI= Received: by 10.210.18.8 with SMTP id 8mr3449984ebr.51.1240657881334; Sat, 25 Apr 2009 04:11:21 -0700 (PDT) Received: from notas (r2ah146.net.upc.cz [62.245.97.146]) by mx.google.com with ESMTPS id 10sm3122702eyz.11.2009.04.25.04.11.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 25 Apr 2009 04:11:21 -0700 (PDT) Date: Sat, 25 Apr 2009 13:11:17 +0200 From: Martin Nagy To: linux-sparse@vger.kernel.org Subject: Re: [PATCH] Print an error if typeof() lacks an argument Message-ID: <20090425131117.30242d75@notas> In-Reply-To: <20090425130343.3df87cbb@notas> References: <20090425130343.3df87cbb@notas> X-Mailer: Claws Mail 3.7.0 (GTK+ 2.12.12; i386-redhat-linux-gnu) Mime-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Martin Nagy wrote: > > We weren't checking if the initializer isn't NULL, which caused sparse > to segfault later on when performing lazy evaluation in classify_type(). > > Signed-off-by: Martin Nagy I accidentally sent this from my work email address, which is different than the sign-off address, sorry. I'm not sure if that's an issue, but just to make sure, I'm sending the patch again. Martin From 962e4b1ad3b3cb13c7427d07dfa44cd15af11693 Mon Sep 17 00:00:00 2001 From: Martin Nagy Date: Sat, 25 Apr 2009 12:56:33 +0200 Subject: [PATCH] Print an error if typeof() lacks an argument We weren't checking if the initializer isn't NULL, which caused sparse to segfault later on when performing lazy evaluation in classify_type(). Signed-off-by: Martin Nagy --- parse.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/parse.c b/parse.c index 9662122..18cfaef 100644 --- a/parse.c +++ b/parse.c @@ -924,12 +924,17 @@ static struct token *typeof_specifier(struct token *token, struct decl_state *ct ctx->ctype.base_type = sym->ctype.base_type; apply_ctype(token->pos, &sym->ctype, &ctx->ctype); } else { - struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF); - token = parse_expression(token->next, &typeof_sym->initializer); - - typeof_sym->endpos = token->pos; - ctx->ctype.base_type = typeof_sym; - } + struct expression *expr; + token = parse_expression(token->next, &expr); + if (expr) { + struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF); + typeof_sym->endpos = token->pos; + typeof_sym->initializer = expr; + ctx->ctype.base_type = typeof_sym; + } else { + sparse_error(token->pos, "expected expression after the '(' token"); + } + } return expect(token, ')', "after typeof"); } -- 1.6.0.6