From patchwork Sun Nov 20 12:18:17 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Brunn X-Patchwork-Id: 12097 Received: from smtprelay01.ispgateway.de ([80.67.18.13]) by www.linuxtv.org with esmtp (Exim 4.50) id 1Edo9D-0002yE-7t for vdr@linuxtv.org; Sun, 20 Nov 2005 13:18:19 +0100 Received: (qmail 25444 invoked from network); 20 Nov 2005 12:18:18 -0000 Received: from unknown (HELO localhost.localdomain) (845114@[85.216.19.19]) (envelope-sender ) by smtprelay01.ispgateway.de (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 20 Nov 2005 12:18:18 -0000 Received: from shire.middleearth ([192.168.1.183]) by localhost.localdomain with esmtp (Exim 4.54) id 1Edo9B-0000Pg-UU for vdr@linuxtv.org; Sun, 20 Nov 2005 13:18:18 +0100 From: Holger Brunn To: VDR Mailing List Date: Sun, 20 Nov 2005 13:18:17 +0100 User-Agent: KMail/1.8.2 References: <438060F3.7030408@cadsoft.de> In-Reply-To: <438060F3.7030408@cadsoft.de> MIME-Version: 1.0 Message-Id: <200511201318.17269.holger.brunn@stud.uni-karlsruhe.de> X-SA-Exim-Connect-IP: 192.168.1.183 X-SA-Exim-Mail-From: holger.brunn@stud.uni-karlsruhe.de X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on Lothlorien X-Spam-Level: X-Spam-Status: No, score=-4.4 required=3.5 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.1.0 Subject: Re: [vdr] Re: cString operator= with same buffer X-SA-Exim-Version: 4.2 (built Fri, 04 Mar 2005 01:30:41 +0100) X-SA-Exim-Scanned: Yes (on localhost.localdomain) X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Nov 2005 12:18:19 -0000 Status: O X-Status: X-Keywords: X-UID: 6263 Klaus Schmidinger on Sunday 20 November 2005 12:41: > A copy ctor would certainly be a good idea. > Please send a patch and let us know if that fixes > your problem. Adding the copy constructor fixes my problem by avoiding it. So I made two patches, both with the copy constructor, one also has a check for equal buffers in operator= and doesn't free them in this case. Greetings Holger diff -Nu vdr-1.3.36-org/tools.c vdr-1.3.36/tools.c --- vdr-1.3.36-org/tools.c 2005-11-20 12:55:37.000000000 +0100 +++ vdr-1.3.36/tools.c 2005-11-20 12:49:01.000000000 +0100 @@ -527,6 +527,11 @@ s = TakePointer ? (char *)S : S ? strdup(S) : NULL; } +cString::cString(const cString &String) +{ + s = String.s ? strdup(String.s) : NULL; +} + cString::~cString() { free(s); diff -Nu vdr-1.3.36-org/tools.h vdr-1.3.36/tools.h --- vdr-1.3.36-org/tools.h 2005-11-20 12:55:39.000000000 +0100 +++ vdr-1.3.36/tools.h 2005-11-20 10:04:51.000000000 +0100 @@ -75,6 +75,7 @@ char *s; public: cString(const char *S = NULL, bool TakePointer = false); + cString(const cString &String); virtual ~cString(); operator const char * () const { return s; } // for use in (const char *) context const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)