Re: Some encoding trouble via libpq
| От | Tom Lane |
|---|---|
| Тема | Re: Some encoding trouble via libpq |
| Дата | |
| Msg-id | 29814.1175197572@sss.pgh.pa.us обсуждение |
| Ответ на | Some encoding trouble via libpq ("Billy Gray" <billy.zophar@gmail.com>) |
| Ответы |
Re: Some encoding trouble via libpq
|
| Список | pgsql-general |
"Billy Gray" <billy.zophar@gmail.com> writes:
> char *buffer = (char *) xmalloc (STDIN_BLOCK); //xmalloc is really
> malloc
> int offset = 0;
> int read = 1;
> int size = STDIN_BLOCK;
> while ( (read > 0) && (offset <= STDIN_MAX) )
> {
> syslog (LOG_DEBUG, "Reading a block...");
> read = fread (buffer + offset, 1, STDIN_BLOCK, stdin);
> offset += read;
> if (read == STDIN_BLOCK)
> {
> size += STDIN_BLOCK;
> buffer = xrealloc (buffer, size);
> }
> } // while
This looks to me like it risks telling fread to read more bytes than
will actually fit in the buffer at the moment. Think about what happens
if fread returns only a partial bufferload on any particular call.
I'm guessing you're clobbering memory ...
regards, tom lane
В списке pgsql-general по дате отправления: