Need help to understand small part of sourcecode

Toomas Soome tsoome at muhv.pri.ee
Sun Dec 30 00:55:02 GMT 2001


On Sun, 30 Dec 2001, Simo Sorce wrote:

>
> Yes I tought it also, but in some places we prefer to get segfaults and fix problems than simply failing functions without apparent reason, I do not know if this is the case, I leave jerry, jeremy and other that better understands the printing code to make a better fix.

hm, default action for assert() is to abort with core....

DESCRIPTION
     The assert() macro inserts  diagnostics  into  applications.
     When  executed,  if  expression  is  FALSE  (zero), assert()
     prints the error message

     Assertion failed: expression, file xyz, line nnn

     on the standard error output and aborts. In the  error  mes-
     sage,  xyz is the name of the source file and nnn the source
     line number of the assert()  statement.  These  are  respec-
     tively  the  values  of the preprocessor macros __FILE__ and
     __LINE__.


>
> On Sun, Dec 30, 2001 at 08:30:48AM +0100, Claudia Moroder wrote:
> > Hello Simo,
> >
> > I see you changed to cvs the way status is passed instead of NULL.
> >
> > For this case this is the solution, but this solutions leaves the door open
> > for similar errors. What about to test in all functions if passed pointers
> > are NULL ?  This checks should be conditionally compiled in this way samba
> > would not be slowed down in the standard case. I remember in windows
> > programmin there was a statement called ASSERT()
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dshow/htm/a
> > ssert.asp .
> > What about to use a similar solution ?
> >
> >
> > Bye
> > Andreas
> >
> > -----Ursprüngliche Nachricht-----
> > Von: "Simo Sorce" <idra at samba.org>
> > An: "andreas moroder" <claudiamoroder at st-ulrich.suedtirol.net>
> > Gesendet: Samstag, 29. Dezember 2001 10:43
> > Betreff: Re: Need help to understand small part of sourcecode
> >
> >
> > > On Fri, Dec 28, 2001 at 11:00:08PM +0100, andreas moroder wrote:
> > > > Hello,
> > > >
> > > > it would be nice if anyone could explain me the following sections of
> > source
> > > > code
> > > >
> > > > In smbd/reply.c  in the function    reply_printqueue ( line 2550 .. )
> > > >
> > > >  print_queue_status(SNUM(conn), &queue,NULL) is called with the 3th
> > parameter
> > > > NULL.
> > >
> > > I think this is a bug.
> > >
> > > >
> > > > in printing/printing.c there is the function print_queue_status
> > > >
> > > > .....
> > > >         ZERO_STRUCTP(status);
> > > >         slprintf(keystr, sizeof(keystr)-1, "STATUS/%s",
> > lp_servicename(snum));
> > > >         key.dptr = keystr;
> > > >         key.dsize = strlen(keystr);
> > > >         data = tdb_fetch(tdb, key);
> > > >         if (data.dptr) {
> > > >                 if (data.dsize == sizeof(*status)) {
> > > >                         memcpy(status, data.dptr, sizeof(*status));
> > <- ??
> > > >
> > > >                 }
> > > >                 SAFE_FREE(data.dptr);
> > > >         }
> > > >
> > > > the line <-?? is not clear to me
> > > >
> > > > if status is passed as NULL, the first parameter of memcopy is NULL. How
> > can
> > > > data.ptr be copied to nowhere ?
> > >
> > > it can't, my bet is that either memcpy see that src is null and return or
> > we get a segfault here.
> > >
> > > >
> > > > Do I miss anything ?
> > > >
> > > > (  I begin to have doubts, that memcpy(status, data.dptr,
> > sizeof(*status))
> > > > copies the pointer data.dptr to the pointer status ( not the data ), but
> > in
> > > > this case the SAFE_FREE would free the data status points )
> > >
> > > no, status is the pointer for a print_status_struct structure, this
> > instruction mean we want to copy the content of data.dptr in the structure!
> > >
> > >
> > > weel spotted, thanks.
> > > --
> > > Simo Sorce       idra at samba.org
> > > -------------------------------
> > > Samba Team http://www.samba.org
> >
> >
>
> --
> Simo Sorce       idra at samba.org
> -------------------------------
> Samba Team http://www.samba.org
>

toomas
-- 
Frankfort, Kentucky, makes it against the law to shoot off a
policeman's tie.





More information about the samba-technical mailing list