A pointer can not be negative - ftp.cc:1269 #1

Zamknięty
opened 6 lat temu by Ghost · 3 komentarzy
Ghost skomentował(-a) 6 lat temu

Here is a bug report from cppcheck:

[ftp.cc:1269]: (style) A pointer can not be negative so it is either pointless or an error to check if it is.

An other one from clang-5.0.2

ftp.cc:1269:22: error:
ordered comparison between pointer and zero ('const char *' and 'int')
if(ftpResponse(-1) <= 0 || (m_iRespType != 2) )

From what I read here and there, a cast to a void pointer can be done.

if(ftpResponse(-1) <= (void*) 0 || (m_iRespType != 2) )

It builds fine, but does the software work as intended?

I've noticed that gcc-4.8.5 and clang-3.0 does build "as is" without complaining.
I stepped upon this while converting to cmake since I use clang-5.0.2 for the building.

Here is a bug report from cppcheck: [ftp.cc:1269]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. An other one from clang-5.0.2 ftp.cc:1269:22: error: ordered comparison between pointer and zero ('const char *' and 'int') if(ftpResponse(-1) <= 0 || (m_iRespType != 2) ) From what I read here and there, a cast to a void pointer can be done. if(ftpResponse(-1) <= (void*) 0 || (m_iRespType != 2) ) It builds fine, but does the software work as intended? I've noticed that gcc-4.8.5 and clang-3.0 does build "as is" without complaining. I stepped upon this while converting to cmake since I use clang-5.0.2 for the building.
SlavekB skomentował(-a) 6 lat temu
Właściciel

Because ftpResponse returns char*, I think that in this case, the purpose is to verify if null has been returned. I would therefore expect the following adjustment:

if( (ftpResponse(-1) == null) || (m_iRespType != 2) )
Because `ftpResponse` returns `char*`, I think that in this case, the purpose is to verify if null has been returned. I would therefore expect the following adjustment: ``` if( (ftpResponse(-1) == null) || (m_iRespType != 2) ) ```
MicheleC skomentował(-a) 6 lat temu
Właściciel

"void" is by definition a null type, so it makes no sense to use order comparison on that, e.g. <= used on a void variable is pretty much a mistake. I believe the best solution is as in tdelibs:

if(!ftpResponse(-1) || (m_iRespType != 2) )

It seems there is quite a bit of duplication between

tde/main/applications/tdeio-ftps/tdeio_ftps/ftp.cc

and

tde/main/tdelibs/tdeioslave/ftp/ftp.cc
"void" is by definition a null type, so it makes no sense to use order comparison on that, e.g. <= used on a void variable is pretty much a mistake. I believe the best solution is as in tdelibs: ``` if(!ftpResponse(-1) || (m_iRespType != 2) ) ``` It seems there is quite a bit of duplication between ``` tde/main/applications/tdeio-ftps/tdeio_ftps/ftp.cc ``` and ``` tde/main/tdelibs/tdeioslave/ftp/ftp.cc ```
SlavekB skomentował(-a) 6 lat temu
Właściciel

Resolved - used solution identical to tdelibs.

Resolved - used solution identical to tdelibs.
SlavekB zamknął(-ęła) to zgłoszenie 6 lat temu
SlavekB dodaje to do kamienia milowego R14.0.6 release 6 lat temu
Zaloguj się, aby dołączyć do tej rozmowy.
Brak kamienia milowego
Brak przypisanych
Uczestnicy 3
Powiadomienia
Termin realizacji

Brak ustawionego terminu realizacji.

Zależności

No dependencies set.

Reference: TDE/tdeio-ftps#1
Ładowanie…
Nie ma jeszcze treści.