- use strncmp instead of strstr
This commit is contained in:
12
ascon.c
12
ascon.c
@ -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 */
|
||||
@ -229,7 +232,7 @@ int AsconConnectSuccess(int fd)
|
||||
ret = ASCON_RECV_ERROR; /* first recv failed */
|
||||
}
|
||||
} else {
|
||||
if(FD_ISSET(fd,&wmask)){
|
||||
if (FD_ISSET(fd,&wmask)) {
|
||||
if (send(fd, NULL, 0, 0) < 0) { /* zero length, check only return value */
|
||||
ret = ASCON_SEND_ERROR; /* first send failed */
|
||||
}
|
||||
@ -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 */
|
||||
|
Reference in New Issue
Block a user