Re: problem with memory allocation

Поиск
Список
Период
Сортировка
От Kjetil Haaland
Тема Re: problem with memory allocation
Дата
Msg-id 200411281433.13973.kjetil.haaland@student.uib.no
обсуждение исходный текст
Ответ на Re: problem with memory allocation  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-novice
On Friday 26 November 2004 17:52, Stephan Szabo wrote:

> That's because AFAICS you're misusing the output of palloc as a string
> when you haven't put a string into it.  After allocation, it seems you
> have two pointers, one which has secondStart bytes allocated, the other
> which has strlen(align->stringBuffer)-secondStart+1 bytes allocated. The
> values of the bytes inside those allocated bytes are technically
> indeterminate, so using %s or strlen on them is invalid.
>
> More fundamentally, it feels like you're trying to use strlen() to get the
> size of the allocated space [in statements like first[strlen(first)]='\0']
> which is not what strlen does. Strlen generally moves through memory
> starting at the pointer looking for a '\0' character and if one does not
> exist within the size you've allocated, the behavior is undefined.
> first[strlen(first)]='\0' is pretty much a no op, since either it found a
> \0 character within the buffer (in which case that should already be a
> \0 or went off the end of the buffer (in which case you can't rely on
> strlen returning something meaningful, and even if it did, it's not in the
> object, so you shouldn't be writing to it anyway).

Hello again
Thanks a lot for a great answer! The problem was as you said my misuse of
strlen and the insertion of '\0'. I used the numbers that i used when i
allocated the space to insert the '\0' and now it works!

- Kjetil

В списке pgsql-novice по дате отправления:

Предыдущее
От: malini bu
Дата:
Сообщение: how to unsubscribe
Следующее
От: "Jeff Flowers"
Дата:
Сообщение: Re: how to unsubscribe