[prev in list] [next in list] [prev in thread] [next in thread] 

List:       net-snmp-coders
Subject:    Re: Fwd: SF.net SVN: net-snmp:[18053] trunk/net-snmp
From:       Magnus Fromreide <magfr () lysator ! liu ! se>
Date:       2010-01-24 16:39:59
Message-ID: 1264351199.31826.40.camel () sara ! home
[Download RAW message or body]

On Sun, 2010-01-24 at 16:45 +0100, Bart Van Assche wrote:
> Hello Magnus,

Hello.

> As far as I know until now the following convention was used in the
> Net-SNMP source tree:
> * Character strings owned by a data structure and that have to be
> freed when the data structure itself is deallocated are declared as
> char *.
> * Character strings not owned by a data structure and that must not be
> freed when the data structure itself is deallocated are declared as
> const char*.

Oh. Then this is actually a quite interesting question.

I tend to think that const T* data members are those where the pointed
to data shouldn't be changed during the lifetime of the object, at least
not from this reference.

Note that ownership is unrelated to constness from my point of view.

> You are changing this convention.

I have never seen any such convention mentioned.

> Furthermore, this particular patch has the disadvantage that the
> compiler will no longer issue a warning when a coder forgets to
> strdup() a string before assigning it to
> subtree_context_cache.context_name.

This is true.
But not adding the patch have the disadvantage that the compiler fails
to warn for unintended writes to the objects

subtree_context_cache *ptr = get_top_context_cache();

if (ptr && ptr->context_name[0] = '\0')
  ...

so then this boils down to what case to protect against.

/MF


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic