- use strncmp instead of strstr

This commit is contained in:
zolliker
2011-04-29 14:07:28 +00:00
parent 446b05d6a2
commit f24ed4e5b6

10
ascon.c
View File

@ -219,9 +219,12 @@ int AsconConnectSuccess(int fd)
ret = uselect(fd + 1, &rmask, &wmask, NULL, &tmo);
if (ret > 0) {
/**
* MK:
* This assertion triggered for some reason: as writing is only done later
* I moved the test for ISSET(wmask) down there
* assert(FD_ISSET(fd, &wmask));
* MZ:
* I remember having found this logic on the www. Anyway, your way must be o.k. too
*/
if (FD_ISSET(fd, &rmask)) { /* there may already be data for read */
@ -498,17 +501,18 @@ int AsconStdHandler(Ascon * a)
/**
* Treat hex strings as terminators right. Note that this
* is limited to single character terminators.
* M.Z. changed strstr to strncmp (more precise)
*/
static void AsconCheckTerminators(Ascon *a)
{
int c;
if(a->sendTerminator != NULL && strstr(a->sendTerminator,"0x") != NULL){
if (a->sendTerminator != NULL && strncmp(a->sendTerminator,"0x",2) == 0) {
sscanf(a->sendTerminator,"%x",&c);
a->sendTerminator[0] = (char)c;
a->sendTerminator[1] = '\0';
}
if(a->replyTerminator != NULL && strstr(a->replyTerminator,"0x") != NULL){
if (a->replyTerminator != NULL && strncmp(a->replyTerminator,"0x",2) == 0) {
sscanf(a->replyTerminator,"%x",&c);
a->replyTerminator[0] = (char)c;
a->replyTerminator[1] = '\0';
@ -579,7 +583,7 @@ int AsconStdInit(Ascon *a, SConnection *con, int argc, char *argv[])
} else {
a->sendTerminator = strdup("\n");
}
if (pars[1] && pars[2] != '\0') {
if (pars[1] && pars[1][0] != '\0') {
a->timeout = atof(pars[1]);
} else {
a->timeout = 2.0; /* sec */