[Click] %{element} syntax

Eddie Kohler kohler at cs.ucla.edu
Wed Mar 10 21:39:03 EST 2010


On 3/10/10 6:03 PM, Ian Rose wrote:
> Hmm really?  That's a bit worrisome.  Is it vsnprintf that you think may
> crash or code that's actually in some elements themselves?

I'd expect something like

click_chatter("%{element} blah %d %s", this, 39, "foo");

to crash when the element pointer is misinterpreted as an integer and 
then "39" is cast to const char *.

> I note that in line 112 of glue.cc, you fall back on just a simple
> vsnprintf if ErrorHandler::default_handler() returns NULL:
>
>> 112 if (ErrorHandler *errh = ErrorHandler::default_handler()) {
>> 113 errh->xmessage(ErrorHandler::e_info, fmt, val);
>> 114 } else {
>  > [...]
>
> So is this behavior also dangerous? Now admittedly, I'm not sure why
> default_handler would ever be NULL, so maybe this is just a "this should
> never happen but if it does let's do our best to print something even if
> its unsafe" type thing?

It is exactly "this should never happen but if it does etc."

> All I am actually trying to do is make click_chatter go to stdout while
> leaving all other errors going to stderr. I guess I could create a new
> FileErrorHandler using stdout instead of stderr and then change line 112
> above to be something like:
>
> if (ErrorHandler *errh = <my-stdout-handler>) {

And that's exactly what I would do.

Eddie



> thanks,
> Ian
>
>
> Eddie Kohler wrote:
>> Ah, OK.
>>
>> Whatever you're doing, I would definitely do it by subclassing
>> ErrorHandler. Elements definitely expect the %{..} syntax to work and
>> you will get crashes if it is ignored.
>>
>> E
>>
>>
>> On 3/10/10 5:47 PM, Ian Rose wrote:
>>> AH HA!
>>>
>>> My mistake - I totally forgot that (normally) click_chatter calls
>>> through an ErrorHandler rather than directly to vsnprintf or the like. I
>>> have changed my glue.cc to NOT use ErrorHandler::default_handler(),
>>> which is why this special syntax is not working for me.
>>>
>>> Sorry about the false alarm there!
>>>
>>> - Ian
>>>
>>>
>>> Eddie Kohler wrote:
>>>> The code that handles this case starts at error.cc:690, if you're
>>>> interested in single stepping.
>>>>
>>>>
>>>> On 3/10/10 4:54 PM, Ian Rose wrote:
>>>>> Hi all -
>>>>>
>>>>> In various places (such as simplequeue.cc), there are lines like this:
>>>>>
>>>>>> click_chatter("%{element}: overflow", this);
>>>>>
>>>>> I'm guessing that this is supposed to print some kind of
>>>>> description/representation of the element, followed by ":
>>>>> overflow", but
>>>>> on my machine (userspace click, FreeBSD 7.2-STABLE) it just prints
>>>>> "{element}: overflow".
>>>>>
>>>>> Does this "work" (as I am assuming its supposed to) for other
>>>>> people or
>>>>> does it print oddly for everyone?
>>>>>
>>>>> - Ian
>>>>> _______________________________________________
>>>>> click mailing list
>>>>> click at amsterdam.lcs.mit.edu
>>>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click


More information about the click mailing list