From owner-freebsd-audit Tue Dec 19 9:29:26 2000 From owner-freebsd-audit@FreeBSD.ORG Tue Dec 19 09:29:24 2000 Return-Path: Delivered-To: freebsd-audit@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id 3FD6937B400; Tue, 19 Dec 2000 09:29:23 -0800 (PST) Received: from billy-club.village.org (billy-club.village.org [10.0.0.3]) by rover.village.org (8.11.0/8.11.0) with ESMTP id eBJHTKs13933; Tue, 19 Dec 2000 10:29:21 -0700 (MST) (envelope-from imp@billy-club.village.org) Received: from billy-club.village.org (localhost [127.0.0.1]) by billy-club.village.org (8.11.1/8.8.3) with ESMTP id eBJHTps36903; Tue, 19 Dec 2000 10:29:51 -0700 (MST) Message-Id: <200012191729.eBJHTps36903@billy-club.village.org> To: Ben Smithurst Subject: Re: printf(1) broken for some long format strings Cc: audit@FreeBSD.ORG In-reply-to: Your message of "Tue, 19 Dec 2000 14:35:06 GMT." <20001219143506.C78749@strontium.scientia.demon.co.uk> References: <20001219143506.C78749@strontium.scientia.demon.co.uk> Date: Tue, 19 Dec 2000 10:29:51 -0700 From: Warner Losh Sender: imp@billy-club.village.org Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <20001219143506.C78749@strontium.scientia.demon.co.uk> Ben Smithurst writes: : + if (len > copy_size) { : + if ((newcopy = realloc(copy, len)) == NULL) : + return NULL; : + copy = newcopy; : + copy_size = len; : + } if (len > copy_size) { if (copy_size == 0) newlen = 1024; else newlen = ((len + 1023) >> 10) << 10; if ((newcopy = realloc(copy, newlen)) == NULL) return NULL; copy = newcopy; copy_size = newlen; } might be a little better. It will round the size to the next highest k boundary, which will result in fewer malloc calls. A slightly better way would be to find some way to round it up to the next power of 2 so that you do even fewer malloc calls, but my bit tiddling foo isn't awake yet this morning. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message