Return to Home
  View the contents of your Cart View cart  
  0 item(s) in cart  
  Checkout  

Gimpel Software - Discussion Forum
Discussion Forum
We invite you to use this forum to communicate with other PC-lint and FlexeLint users. You do not need to log in to post a message. WARNING: Your email address will not be encrypted. We recommend that you obfuscate it as protection from web crawlers. To receive technical support directly from Gimpel Software, please follow the guidelines at http://www.gimpel.com/html/support.htm
Gimpel Software - Discussion Forum
Subject From Date & Time
-sem(Obj::Obj,custodial(t)) Wlad May 12, 2004
9:26:34 AM
  Re: -sem(Obj::Obj,custodial(t)) James Widman May 12, 2004
1:17:08 PM
          Re: -sem(Obj::Obj,custodial(t)) Wlad May 12, 2004
1:25:27 PM
                  Re: -sem(Obj::Obj,custodial(t)) James Widman May 12, 2004
3:56:20 PM
                          Re: -sem(Obj::Obj,custodial(t)) Henrik Johansson May 05, 2010
8:16:20 PM
                                  Re: -sem(Obj::Obj,custodial(t)) David M September 23, 2011
6:56:26 PM
                                          Re: -sem(Obj::Obj,custodial(t)) Michael Kelley November 14, 2011
5:08:28 PM
                                                  Re: -sem(Obj::Obj,custodial(t)) Carl December 30, 2014
4:11:39 PM
                                                          Re: -sem(Obj::Obj,custodial(t)) December 31, 2014
7:30:47 AM
                                                                  Re: -sem(Obj::Obj,custodial(t)) Carl January 27, 2015
10:41:31 AM
 
Subject: -sem(Obj::Obj,custodial(t))
Date: May 12, 2004
9:26:34 AM
Name: Wlad
Message:
Hi.

For the following exmaple PC-Lint 8.0o issues 
Warning 429: "Custodial pointer 'child' has not 
been freed or returned". However, it is freed by 
the 'pa' object as it contains pointer 
to 'child' and calls delete for it in the 
destructor. I understand, that it is not trivial 
for PC-Lint to find this out, so I have 
specified semantic for constructor. But this 
semantic specification does not work. What is 
wrong?


//lint -sem(Obj::Obj,custodial(t))
class Obj {
public:
  Obj() : m_child( static_cast<Obj*>( 0)) {}
  Obj(Obj* parent)
    : m_child( static_cast<Obj*>( 0))
  {
    parent->setChild(this);
  }
  ~Obj()
  {
    try { delete m_child; } catch(...) { }
  }

  void Print() const throw() { }

private:
  void setChild( Obj* o) { m_child = o; }
  Obj* m_child;
};


void main(void)
{
  Obj pa;
  Obj *child = new Obj( &pa);

  pa.Print();
  child->Print();
}
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: May 12, 2004
1:17:08 PM
Name: James Widman
Email: support@gimpel.com
Message:
Hi Wlad, 

The argument to custodial() must be an integer
literal.  (See the entry for custodial() in
section 10.2.1 of the Lint manual.) 
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: May 12, 2004
1:25:27 PM
Name: Wlad
Message:
Hi James,

here is what I read in the manual:

custodial(i) where i is some integer
             denoting the ith argument
             or the letter t denoting
             the this pointer...

I have assumed that -sem(Obj::Obj,custodial(t)) 
will remove custody from 'this' pointer. May be 
you have better idea how to suppress warning 
message described above?
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: May 12, 2004
3:56:20 PM
Name: James Widman
Email: support@gimpel.com
Message:
Hi Wlad, 

D'oh!  I must admit that I only glanced at the
manual this time. 

You are absolutely correct; Lint should be able to
see that the constructor takes custody of "this"
with the option you had originally.  It's an
interesting situation though, because in the case of: 

Obj* child = new Obj( &pa ); 

...Lint needs to be aware that a function (the
constructor) will take custody of an object that
has not yet been created. 

It seems there is a work-around though -- assuming
that, in your actual production code, you intend
to call some member function of Obj (with the
"child" pointer) within the function where that
object is created, e.g.: 

child->Print(); // Obj::Print must be called in
the same scope as "new Obj" for this to work. 

If that's the case, then you can just do: 
//lint -sem(Obj::Print, custodial(t))

...which should work. 

In any event, we do plan to support your first
custodial semantic in a future version of Lint. 

Thanks for the feedback!
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: May 05, 2010
8:16:20 PM
Name: Henrik Johansson
Email: saabgroup
Message:
Is there any development in FlexeLint regarding 
this issue?
See
http://www.gimpel.com/Discussion.cfm?
ThreadID=3441
...for my re-thread of this thread.
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: September 23, 2011
6:56:26 PM
Name: David M
Message:
I'm also trying to figure out a better way to do 
this.  There are multiple popular GUI toolkits that 
follow this type of pattern.  Another request was 
here:

http://www.gimpel.com/Discussion.cfm?ThreadID=2494

I also tried suppressing with -etype, but this 
error doesn't seem to have type info.
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: November 14, 2011
5:08:28 PM
Name: Michael Kelley
Email: michael.kelley@navteq.com
Message:
I'm bumping this question as I have a similar 
problem.  I have a function that looks like this:

class TiXmlNode
{
   .
   .
   .
	TiXmlNode* LinkEndChild( TiXmlNode* 
addThis );
};

and I try to suppress warning #429 by doing this:

//lint -
sem(TiXmlElement::LinkEndChild,custodial(t))

Unfortunately my suppression is unsuccessful.

Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: December 30, 2014
4:11:39 PM
Name: Carl
Message:
Bumping this again.
Has any progress been made on allowing
constructors to take custodial ownership of memory?

Code such as the following results in a 429 :
Custodial pointer 'entPtr' (line 218) has not
    been freed or returned

EntryPtr clone(const std::string& newType) {
  Entry* entPtr = 0;
  entPtr = new Entry(newType);
  EntryPtr result(entPtr);
  return result;
}

Trying a twist on James's earlier suggestion, I
though maybe Lint could be tricked into letting
the destructor take ownership, since no other
methods are called, but that didn't work:

-sem(EntryPtr::EntryPtr,custodial(1))
-sem(EntryPtr::EntryPtr,custodial(t))
-sem(EntryPtr::~EntryPtr,custodial(1))
-sem(EntryPtr::~EntryPtr,custodial(t))

There doesn't seem to be any way yet as of 9.00K
to allow this to be indicated to PC Lint.
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: December 31, 2014
7:30:47 AM
Message:
Here is my suggestion for a workaround:
  //lint -esym(429,EntryPtr)

and for the above example:
  //lint -esym(429,child)

Lucky are the ones who followed a naming
convention. Then a single wild card suppression
might be enough to suppress all issues.
  //lint -esym(429,*child*)

Of cause there is a danger to suppress to much. 

Ralf
Reply to this Message! Previous Message Next Message
 
Subject: Re: -sem(Obj::Obj,custodial(t))
Date: January 27, 2015
10:41:31 AM
Name: Carl
Email: Carl
Message:
Gimpel support confirmed that this is not
currently possible in Lint 9L.  They suggested
that I post to their Feedback Forum so that other
users could vote on the idea for future
consideration.  It is posted at:

http://support.gimpel.com/forums/225702-general/suggestions/7016701-allow-lint-to-see-that-constructor-takes-ownership
Reply to this Message! Previous Message Next Message