Re: C client to load binary data to MySQL
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 04 Nov 2006 12:26:30 +0000
Jens Thoms Toerring wrote:
Me Alone <me@xxxxxxxx> wrote:
<snip>
That should do exactly the same.
p = query + strlen(query);
while ((from_len = fread(buf, 1, sizeof(buf), pic)) > 0)
{
/* don't overrun end of query buffer! */
if (p + (2*from_len) + 3 > query + sizeof(query))
From a nit-picky point of view this is not 100% correct - according
to the C standard you're only allowed to compare pointers pointing
witin the same object. But in case 'p + 2 * from_len + 3' is too
large this expression already points outside of 'query'.
However, by applying a little algebra we can get a test that does not have this problem. Subtract query from both sides of the expression and we get:
if ((p - query) + (2*from_len) + 3 > sizeof(query))
This is valid on any implementation as long as both pointers are in to the same object, the difference between them can be represented and we don't have anything else causing an arithmetic overflow. Since one is unlikely to be constructing a query string anywhere even close to 30000 characters long I would say this makes it safe for all implementations without being any harder to read.
> In order
not to violate this constraint you would need to e.g. use a counter
of how much you already have used of 'query' and compare to that.
But I don't think that this is the real problem..
I agree with you. However I don't see any good reason to leave this unfixed seeing as the fix is so simple.
<snip>
if ((fromImage=load_image(mysql)) > 0)
fprintf(stderr, "%d", fromImage);
And here's definitely a problem: you call your function for putting
the image into the database (load_image() seems to be a mis-nomer for
<snip>
To the OP, if you need further help with the MySQL parts of this, such as the load_image function and connecting to the database, please take it to a suitable group, possibly one with mysql or database in its name, or the MySQL mailing lists. This group is for discussing C, not the myriads of third party libraries which have their own groups and mailing lists.
--
Flash Gordon
.
- References:
- C client to load binary data to MySQL
- From: Me Alone
- Re: C client to load binary data to MySQL
- From: Jens Thoms Toerring
- C client to load binary data to MySQL
- Prev by Date: Re: C client to load binary data to MySQL
- Next by Date: Re: scope of struct definitions
- Previous by thread: Re: C client to load binary data to MySQL
- Next by thread: Re: re-definition of standard types
- Index(es):
Relevant Pages
|