Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72676 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57176 invoked from network); 18 Feb 2014 10:42:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2014 10:42:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.181 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.128.181 mail-ve0-f181.google.com Received: from [209.85.128.181] ([209.85.128.181:47474] helo=mail-ve0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/31-64799-B0933035 for ; Tue, 18 Feb 2014 05:42:20 -0500 Received: by mail-ve0-f181.google.com with SMTP id cz12so13490928veb.12 for ; Tue, 18 Feb 2014 02:42:17 -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:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=S9GM+3p7wiS1kF1vqjGIgzvd1PCe3JTQcHXey3N4wo8=; b=ZqINbwl2/xi68G6+2WeV6h5EDKwlYcMHbWqhbe6iNhYphcDnUl59dTT+wf4S00n8Ks fgClHhWziSJQdj00s7/nlVP5DeP4Zwo46P4H0+7LvnFyu3Ccy0Rio06fftcfqVLvZEgM AXCRV1oCYfqXHe0SnpENa4av3ieeAM+nRTAS4x6xTr6+Omc28d0u2sDO+V8YfO18ulUS u4VFXKgiVFlXYVn7iw8ffLkYM7nB8tk3BgN3RPmXiDWTcKOlWMSMk6X15Gg5otflj9iI BzHhkYa0Prfv7FdXedWR7fI37KDlXNDjp2MZaD3hV7XqT/L60FL8mKSdiBaZCLvwY+6W WNxA== X-Received: by 10.220.133.80 with SMTP id e16mr20647396vct.13.1392720137223; Tue, 18 Feb 2014 02:42:17 -0800 (PST) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.221.8.129 with HTTP; Tue, 18 Feb 2014 02:41:37 -0800 (PST) In-Reply-To: <1392669755.3990.291.camel@guybrush> References: <1392669755.3990.291.camel@guybrush> Date: Tue, 18 Feb 2014 11:41:37 +0100 X-Google-Sender-Auth: 8sE9tunzMZ1Fy4qN-beGJbCsXO8 Message-ID: To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= Cc: PHP internals list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Usin ClangStatic Analyzer for zend_parse_parameters From: jpauli@php.net (Julien Pauli) On Mon, Feb 17, 2014 at 9:42 PM, Johannes Schl=FCter wrote: > Hi, > > we have the plan to change types we use for zval data. A common place we > use this in is the family of zend_parse_[method_]parameters[_ex] > functions. The issue there is that those a variadic so the compiler > won't notice mistakes. As I was looking into clang internals a bit I > decided to create a plugin to clang's static analyzer to help with this. > The result can be found on > https://github.com/johannes/clang-php-checker/ > > If you get it compiled and working it can detect such things: > > $ cat foo.c > int zend_parse_parameters(int ht, char *, ...); > > #define FORMAT "lsd" > > char *get_format(int a) { > if (!a) { > return 0; > } > return FORMAT; > } > > int **get_location_for_int(); > > void foo() { > char *c; > int i; > > extern int x; > char *format =3D get_format(x); > zend_parse_parameters(0, format, get_location_for_int(), &c, > &i); > } > > > $ clang -cc1 -analyze -analyzer-checker=3Dphp.ZPPChecker \ > -load ./PHPChecker.so foo.c > foo.c:20:3: warning: Type of passed argument &SymRegion{conj_$3{i= nt **}} is of type int ** which did not match expected long * (aka. long *)= for modifier 'l' at offset 3 > zend_parse_parameters(0, format, get_location_for_int(), &c, &i= ); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~ > foo.c:20:3: warning: Too few arguments for format "lsd" while che= cking for modifier 'd' > zend_parse_parameters(0, format, get_location_for_int(), &c, &i= ); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~ > 2 warnings generated. > > > The part of "&SymRegion{conj_$3{int **}}" isn't really nice, yet, > usually you will have variable names there which will be printed > instead, this example was supposed to show a more complex case. (this > example is held simple and missing i.e. TSRM parameters, they are > supported in ZTS and non-ZTS-mode) > > Running this over one of my PHP builds I got those error reports: > http://schlueters.de/zppcheck/ maybe somebody wants to go through them > and fix at least the trivial ones. > > > The checker plugin currently only knows about PHP 5.5's zpp modifiers, > support for the size_t branch will be added (it's trivial to add, I'm > happy about pull requests, check for PHPSample in the code!) > > If there is interest we can add such checks for other PHP-specific > things. > > johannes > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Not sure about some :-p https://github.com/jpauli/php-src/compare/zpp_type_fixed Julien