Hi Julien,

On Mon, Nov 08, 2010 at 12:05:31PM +0100, pichon julien wrote:
> I issue a call to db_conn_query without calling before
> db_conn_connect, and this result in a crash of the lib.
> 
> So what do you think about the following patch ?

I absolutely second your patch: In my opinion, a library should never
crash an application (if it is in the libraries power to detect the
problem), no matter how stupid the application behaves.

I think I'd actually add some more argument checking to the
"dbd_geterror" function:

-- 8< --
 int dbd_geterror(dbi_conn_t *conn, int *errno, char **errstr) {
   int retval = 0;
   int tmp;

   if ((errno == NULL) && (errstr == NULL))
     return (-EINVAL);

   if ((conn == NULL) || (conn->connection == NULL)) {
     if (errno != NULL) {
       *errno = EINVAL;
       retval += 1;
     }
     if (errstr != NULL) {
       *errstr = strdup ("Invalid argument");
       retval += 2;
     }
     return (retval);
   }

   tmp = mysql_errno((MYSQL *)conn->connection);
   if (errno != NULL) {
     *errno = tmp;
     retval += 1;
   }
   if (errstr != NULL) {
     *errstr = strdup (mysql_error((MYSQL *)conn->connection));
     retval += 2;
   }

   return (retval);
 } /* int dbd_geterror */
-- >8 --

This way each pointer may be NULL and the function will still do the
best possible thing, and if it is only to inform the calling code that
it doesn't like being called like that ;) I know that it looks like a
lot of overhead, but being able to throw crap at a library which will
still behave is worth its weight in gold ;)

Regards,
--octo
-- 
Florian octo Forster
Hacker in training
GnuPG: 0x0C705A15
http://octo.it/

Attachment: signature.asc
Description: Digital signature

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Libdbi-drivers-devel mailing list
Libdbi-drivers-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel

Reply via email to