Hi

Aaron Stone wrote:

Actually we're both wrong!

if (!fgets(tmpline, MAX_LINE_SIZE, instream);
    break;

Because fgets returns NULL for an empty line, tmpline's memory is lost.
So we should also check if tmpline is NULL, and if it isn't, free it. (or am I missing something here?)

I'm putting together more patches and will post them to the SourceForge site
this evening. BTW - do you mind GNU GCC extensions? I quickly implemented the
db_get_result_...() functions (there's u64, int and bool versions) as macros
like so:
I guess (almost) everyone is using GCC to compile DBMail, so it shouldn't really be a problem. It might be cleaner to use functions though, even if it's only for making code more readable, don't you think?

#define db_get_result_int(row, field) \
        ({ \
                char *tmp; \
                tmp = db_get_result(row, field); \
                ( tmp ? atoi(tmp) : 0 ); \
        })
#define db_get_result_bool(row, field) \
        ({ \
                char *tmp; \
                tmp = db_get_result(row, field); \
                ( tmp ? ( atoi(tmp) ? 1 : 0 ) : 0 ); \
        })
#define db_get_result_u64(row, field) \
        ({ \
                char *tmp; \
                tmp = db_get_result(row, field); \
                ( tmp ? strtoull(tmp, NULL, 10) : 0 ); \
        })


({ expression; expression; expression; }) is a GNU extension that takes on the
value of the last expression in the block. Lazy stuff. If you'd rather see
these done as functions, it's two seconds work to move them into db.c
I'm not that familiar with GCC macros (mostly just use them for constants), but this kind of macro looks like some real magic stuff :).

I guess we should make these macros into functions. Those are cleaner, and easier to debug.

Ilja


tmpline = fgets(tmpline, MAX_LINE_SIZE, instream);
if (!tmpline)
   break;



--
_______________________________________________
Dbmail-dev mailing list
Dbmail-dev@dbmail.org
http://twister.fastxs.net/mailman/listinfo/dbmail-dev

Reply via email to