- use strncmp instead of strstr
This commit is contained in:
10
ascon.c
10
ascon.c
@ -219,9 +219,12 @@ int AsconConnectSuccess(int fd)
|
|||||||
ret = uselect(fd + 1, &rmask, &wmask, NULL, &tmo);
|
ret = uselect(fd + 1, &rmask, &wmask, NULL, &tmo);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
/**
|
/**
|
||||||
|
* MK:
|
||||||
* This assertion triggered for some reason: as writing is only done later
|
* This assertion triggered for some reason: as writing is only done later
|
||||||
* I moved the test for ISSET(wmask) down there
|
* I moved the test for ISSET(wmask) down there
|
||||||
* assert(FD_ISSET(fd, &wmask));
|
* 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 */
|
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
|
* Treat hex strings as terminators right. Note that this
|
||||||
* is limited to single character terminators.
|
* is limited to single character terminators.
|
||||||
|
* M.Z. changed strstr to strncmp (more precise)
|
||||||
*/
|
*/
|
||||||
static void AsconCheckTerminators(Ascon *a)
|
static void AsconCheckTerminators(Ascon *a)
|
||||||
{
|
{
|
||||||
int c;
|
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);
|
sscanf(a->sendTerminator,"%x",&c);
|
||||||
a->sendTerminator[0] = (char)c;
|
a->sendTerminator[0] = (char)c;
|
||||||
a->sendTerminator[1] = '\0';
|
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);
|
sscanf(a->replyTerminator,"%x",&c);
|
||||||
a->replyTerminator[0] = (char)c;
|
a->replyTerminator[0] = (char)c;
|
||||||
a->replyTerminator[1] = '\0';
|
a->replyTerminator[1] = '\0';
|
||||||
@ -579,7 +583,7 @@ int AsconStdInit(Ascon *a, SConnection *con, int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
a->sendTerminator = strdup("\n");
|
a->sendTerminator = strdup("\n");
|
||||||
}
|
}
|
||||||
if (pars[1] && pars[2] != '\0') {
|
if (pars[1] && pars[1][0] != '\0') {
|
||||||
a->timeout = atof(pars[1]);
|
a->timeout = atof(pars[1]);
|
||||||
} else {
|
} else {
|
||||||
a->timeout = 2.0; /* sec */
|
a->timeout = 2.0; /* sec */
|
||||||
|
Reference in New Issue
Block a user