From patchwork Wed Feb 4 16:38:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 5778131 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B8DEA9F302 for ; Wed, 4 Feb 2015 16:38:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0DDF920253 for ; Wed, 4 Feb 2015 16:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA3D3200E0 for ; Wed, 4 Feb 2015 16:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966526AbbBDQiU (ORCPT ); Wed, 4 Feb 2015 11:38:20 -0500 Received: from mail-qc0-f172.google.com ([209.85.216.172]:60721 "EHLO mail-qc0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966389AbbBDQiT (ORCPT ); Wed, 4 Feb 2015 11:38:19 -0500 Received: by mail-qc0-f172.google.com with SMTP id x3so2100676qcv.3 for ; Wed, 04 Feb 2015 08:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=liR2UDFFe3KB7H5+HASCUWzTn4tj7qHwuq6yrUPjLQY=; b=i5QSh83nNQEvwAvUaS9ykovBCYuKaEUIoS1RBjj+pOZ2F5bnDVs/qPH0yJwHLYhowd uWKPGDy7Z9hoebihbeW+wtoCzxNljpS3uSXEsoktlBWELoW4vzvhpTS57WlwwAdg0IBF ldWFSGqxiA3hGv+W0skKhfbcoyuZDBcgr8unNQV1nl84Tjcj2S94sT1mdAG3nCGg7vAO twoKtNy3O08e+u9yfQWH9GaXs5DOkQN+bLVzOjT/zrSTvWsK8kjPXxGzjarW2ekyVhV2 2s73bGSMgKyPxsQsjXp4aE6uM1RJbG0ROKwJQ4Tu48N3dysyQ6seMOSm/KCXC/DeRiUy gT/A== MIME-Version: 1.0 X-Received: by 10.224.86.74 with SMTP id r10mr2443671qal.45.1423067899320; Wed, 04 Feb 2015 08:38:19 -0800 (PST) Received: by 10.140.102.201 with HTTP; Wed, 4 Feb 2015 08:38:19 -0800 (PST) In-Reply-To: References: <87y4ojhq2f.fsf@rasmusvillemoes.dk> <20150131012339.GA3460@macpro.local> <87386mvcxh.fsf@rasmusvillemoes.dk> <20150204020059.GA7069@macpro.local> <20150204062250.GA9989@macbook.lan> Date: Wed, 4 Feb 2015 08:38:19 -0800 X-Google-Sender-Auth: 2p08uRLLfmUYJEFrsnKLf2URYKU Message-ID: Subject: Re: [PATCH v2] Avoid reusing string buffer when doing string expansion From: Christopher Li To: Luc Van Oostenryck Cc: Rasmus Villemoes , Linux-Sparse Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Feb 4, 2015 at 12:01 AM, Christopher Li wrote: > > When the lexer process the escape char, you did not know the string > is wide char or not. That can be changed after the macro expansion. With that in mind, we can't actually perform the escape char substitution before the pre-processor stage. Here is an untested patch adding the immutable string to macro body. I need to double check if the macro arguments needs it as well. Can you guys try it on the test case you have? Thanks Chris the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/char.c b/char.c index 08ca223..7f86b8a 100644 --- a/char.c +++ b/char.c @@ -123,7 +123,7 @@ struct token *get_string_constant(struct token *token, struct expression *expr) len = MAX_STRING; } - if (len >= string->length) /* can't cannibalize */ + if (string->immutable || len >= string->length) /* can't cannibalize */ string = __alloc_string(len+1); string->length = len+1; memcpy(string->data, buffer, len); diff --git a/pre-process.c b/pre-process.c index 1aa3d2c..57d84b9 100644 --- a/pre-process.c +++ b/pre-process.c @@ -1259,8 +1259,16 @@ static struct token *parse_expansion(struct token *expansion, struct token *argl } else { try_arg(token, TOKEN_MACRO_ARGUMENT, arglist); } - if (token_type(token) == TOKEN_ERROR) + switch (token_type(token)) { + case TOKEN_ERROR: goto Earg; + + case TOKEN_STRING: + case TOKEN_WIDE_STRING: + token->string->immutable = 1; + default: + ; + } } token = alloc_token(&expansion->pos); token_type(token) = TOKEN_UNTAINT; diff --git a/token.h b/token.h index 8dbd80f..af66b2b 100644 --- a/token.h +++ b/token.h @@ -164,7 +164,8 @@ enum special_token { }; struct string { - unsigned int length; + unsigned int length:31; + unsigned int immutable:1; char data[]; }; -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in