Re: I need help, about c++ pointer

Поиск
Список
Период
Сортировка
От Guillaume Lelarge
Тема Re: I need help, about c++ pointer
Дата
Msg-id 200907151638.13780.guillaume@lelarge.info
обсуждение исходный текст
Ответ на I need help, about c++ pointer  (Quan Zongliang <quanzongliang@gmail.com>)
Ответы Re: I need help, about c++ pointer  (Quan Zongliang <quanzongliang@gmail.com>)
Re: I need help, about c++ pointer  (Quan Zongliang <quanzongliang@gmail.com>)
Список pgadmin-support
Hi,

Le mercredi 15 juillet 2009 à 14:04:27, Quan Zongliang a écrit :
> [...]
> I ceate some pointers with:
>
>     SQLWCHAR** stmtlabels = m_srcodbc->GetResultColLabels();
>     m_curstmtlabels = new SQLWCHAR*[m_curstmtcolsnum];
>     for (colidx=0; colidx<m_curstmtcolsnum; colidx++)
>         if (stmtlabels[colidx])
>         {
>             m_curstmtlabels[colidx] = new
> SQLWCHAR[wcslen(stmtlabels[colidx])+1]; wcscpy(m_curstmtlabels[colidx],
> stmtlabels[colidx]);
>         }
>         else
>             m_curstmtlabels[colidx] = NULL;
>
> delete them with:
>
>     if (m_curstmtlabels)
>     {
>         SQLSMALLINT colidx;
>         for (colidx=0; colidx<m_curstmtcolsnum; colidx++)
>             if (m_curstmtlabels[colidx])
>                 delete[] m_curstmtlabels;
>     }
>
> When delete pointers, the first loop is ok.
> But the sencond loop get a crash.
> It seems the first loop delete second array too.
> How to correct it?
>

Shouldn't you do this?

if (m_curstmtlabels)
{ SQLSMALLINT colidx; for (colidx=0; colidx<m_curstmtcolsnum; colidx++)   if (m_curstmtlabels[colidx])     delete
m_curstmtlabels[colidx];
}

BTW, it would have been better on pgadmin-hackers :)

> BTW:
> wcscpy, wcscmp, wcslen ... functions can be supported by all platforms?
>

I suppose so, but I'm not really sure.


--
Guillaume.http://www.postgresqlfr.orghttp://dalibo.com


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

Предыдущее
От: Guillaume Lelarge
Дата:
Сообщение: Re: forgot my password
Следующее
От: Quan Zongliang
Дата:
Сообщение: Re: I need help, about c++ pointer