From owner-freebsd-current@FreeBSD.ORG Wed Sep 8 16:39:08 2010 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4B8FD10656D9; Wed, 8 Sep 2010 16:39:08 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id 106368FC08; Wed, 8 Sep 2010 16:39:07 +0000 (UTC) Received: from critter.freebsd.dk (critter.freebsd.dk [192.168.61.3]) by phk.freebsd.dk (Postfix) with ESMTP id 189A53F5B7; Wed, 8 Sep 2010 16:39:07 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.14.4/8.14.4) with ESMTP id o88Gd6qM067158; Wed, 8 Sep 2010 16:39:06 GMT (envelope-from phk@critter.freebsd.dk) To: mdf@FreeBSD.org From: "Poul-Henning Kamp" In-Reply-To: Your message of "Wed, 08 Sep 2010 08:51:57 MST." Date: Wed, 08 Sep 2010 16:39:06 +0000 Message-ID: <67157.1283963946@critter.freebsd.dk> Sender: phk@critter.freebsd.dk Cc: freebsd-current@FreeBSD.org Subject: Re: deprecating sprintf(9) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 16:39:08 -0000 In message , mdf@ FreeBSD.org writes: >It seems like a large project, but OTOH sprintf(9) is mighty unsafe in >the kernel. Well, it is only unsafe if people used it without knowing what they are doing, so I think a wholesale automated replacement is both unwarranted and inadvisable. I can recommend the following macro for the static buffer cases, it checks if people know what they are doing with an assert. #define bprintf(buf, fmt, ...) \ do { \ assert(snprintf(buf, sizeof buf, fmt, __VA_ARGS__) \ < sizeof buf); \ } while (0) Poul-Henning -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.