Re: TLegend::AddEntry crashes if obj=0 && label=""

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Mon, 24 Aug 2009 12:20:02 +0200


Thanks Chris for your report and perfectly valid suggestion. Now in the SVN trunk.

Rene Brun

Christopher Backhouse wrote:
> Hi,
>
> I have a crash with TLegend, when calling AddEntry with obj=0 and
> label="" (I am abusing this function to produce internal spacing in
> the legend).
> TLegend seems to be happy with null objects in general, and merely
> passing label=" " works around this problem.
>
> At line 229 in TLegend.cxx there is:
>
> if ((obj && !label) || strlen(label)==0) lab = obj->GetTitle();
>
> which is the line that crashes, it is attempting to protect against
> null 'obj' but it appears to be misbracketed. I would suggest:
>
> if (obj && (!label || strlen(label)==0)) lab = obj->GetTitle();
>
> This simple change ought to prevent dereferencing of null obj, and
> allow me to continue misusing TLegend :)
>
> Thanks - Chris
Received on Mon Aug 24 2009 - 12:19:35 CEST

This archive was generated by hypermail 2.2.0 : Mon Aug 24 2009 - 17:50:02 CEST