A
A.A
int db_is_fld_empty(char *fld)
{
return (fld && *fld)?0:1;
}
{
return (fld && *fld)?0:1;
}
Roman said:Hello, All!
I assume my post isn't offtopic here.
I used 'valgrind' utility (guess plenty if you know and use it) for my
application and I got the message "Invalid read of size 1" regarding this
pieice of code:
int db_is_fld_empty(char *fld)
{
return ( !strcmp(fld, "") ? 1 : 0 );
}
Seems like it doesn't like rmpty string I compare with or it's something
more serious?
int db_is_fld_empty(char *fld)
{
return ( !strcmp(fld, "") ? 1 : 0 );
}
Seems like it doesn't like rmpty string I compare with or it's something
more serious?
I tried to wrap it out in 'if-then' statement, but still get same warnings
from valgrind:
if (fld != NULL)
return ((x && *x) ? 0 : 1);
else
return 0;
Roman said:Hello, Robert!
You wrote on 9 Dec 2005 19:39:13 -0800:
??>> this pieice of code: int db_is_fld_empty(char *fld) { return (
??>> !strcmp(fld, "") ? 1 : 0 ); } Seems like it doesn't like rmpty string
??>> I compare with or it's something more serious?
RG> <OT> You are calling this function with a null pointer which then gets
RG> passed to strcmp. It is undefined behavior to pass such a pointer to
RG> strcmp and valgrind caught this. The empty string is okay. </OT>
What is way to bypass this? Is it enough to include checking:
if ( fld != NULL)
return ( !strcmp(fld, "") ? 1 : 0 );
else
return 0;
Mark said:this is virtually a macro. Bear in mind that all you care about is if
the first character of fld is non null
#define DB_IS_FLD_EMPTY(x) (((x)&&(*x))?0:1)
The indirection operator should be outside of the parenthesis:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.