Re: [Gambas-user] [CRASH REPORT] XmlElement.GetAttribute (gb.xml) segfault if the attribute is an empty string
Le 13/09/2016 à 14:40, Adrien Prokopowicz a écrit : > > Damn Tobias, you're fast ! I saw your message just when I commited my > fixes. > I think that overwrote it, but thanks still. :) > > I took the opportunity to spread the fix to the .GetAttribute() method, > which works > the same way. > > However, this raised a question to me : Shouldn't be GB.ReturnNewString() > return null > when either the length or the value is null, instead of just crashing ? > > Regards, > GB.ReturnNewString() returns a void string only if its length argument is zero AND if its value argument is NULL. If the length is zero, or lower than zero, and if the value is not NULL, then strlen() is called on the value. It behaves like that to be backward-compatible with older version of Gambas. But then it prints a big warning on the error output to ask to use GB.ReturnNewZeroString() instead. Regards, -- Benoît Minisini -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] [CRASH REPORT] XmlElement.GetAttribute (gb.xml) segfault if the attribute is an empty string
Le Tue, 13 Sep 2016 14:00:44 +0200, Tobias Boegea écrit: > On Tue, 13 Sep 2016, adamn...@gmail.com wrote: >> Hello, >> >> Damned, my program crashed Gambas that way : >> >> The segfault occurs when I attempt to get the value of the argname >> attribute thus: >> hAD = New CArgDef >> With hAD >> .ShortName = hArg.Attributes["shortname"] >> .LongName = hArg.Attributes["longname"] >> .ArgName = hArg.Attributes["argname"] >> ... >> >> This happens if an XMLElement has an attribute whose value is an empty >> string, for example : >> >> >> >> The argname attribute won't parse and the segfault occurs. >> >> I don't know whether such empty string attributes are "legal" in XML >> though. >> > > They say here [1] that it is valid in the way you wrote it. In revision > #7911 > it doesn't crash anymore and returns an empty string. The fix consisted > of > adding the magical quartet of the C programming language: `?:""'. > > Regards, > Tobi > > [1] > http://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-a-value-valid > Damn Tobias, you're fast ! I saw your message just when I commited my fixes. I think that overwrote it, but thanks still. :) I took the opportunity to spread the fix to the .GetAttribute() method, which works the same way. However, this raised a question to me : Shouldn't be GB.ReturnNewString() return null when either the length or the value is null, instead of just crashing ? Regards, -- Adrien Prokopowicz -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] [CRASH REPORT] XmlElement.GetAttribute (gb.xml) segfault if the attribute is an empty string
On Tue, 13 Sep 2016, adamn...@gmail.com wrote: > Hello, > > Damned, my program crashed Gambas that way : > > The segfault occurs when I attempt to get the value of the argname attribute > thus: > hAD = New CArgDef > With hAD > .ShortName = hArg.Attributes["shortname"] > .LongName = hArg.Attributes["longname"] > .ArgName = hArg.Attributes["argname"] > ... > > This happens if an XMLElement has an attribute whose value is an empty > string, for example : > > > > The argname attribute won't parse and the segfault occurs. > > I don't know whether such empty string attributes are "legal" in XML though. > They say here [1] that it is valid in the way you wrote it. In revision #7911 it doesn't crash anymore and returns an empty string. The fix consisted of adding the magical quartet of the C programming language: `?:""'. Regards, Tobi [1] http://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-a-value-valid -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
[Gambas-user] [CRASH REPORT] XmlElement.GetAttribute (gb.xml) segfault if the attribute is an empty string
Hello, Damned, my program crashed Gambas that way : The segfault occurs when I attempt to get the value of the argname attribute thus: hAD = New CArgDef With hAD .ShortName = hArg.Attributes["shortname"] .LongName = hArg.Attributes["longname"] .ArgName = hArg.Attributes["argname"] ... This happens if an XMLElement has an attribute whose value is an empty string, for example : The argname attribute won't parse and the segfault occurs. I don't know whether such empty string attributes are "legal" in XML though. hth bruce -- B Bruen-- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user