From 02015668e2a1ae7abd2f83c6cf3aa5afb3e4be95 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Wed, 17 Sep 2008 08:39:33 +1000 Subject: [PATCH] Mark Lesha fixed some bugs associated with "send" r2692 | ffr | 2008-09-17 08:39:33 +1000 (Wed, 17 Sep 2008) | 2 lines --- site_ansto/orhvps.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/site_ansto/orhvps.c b/site_ansto/orhvps.c index 01a333a9..453691fd 100644 --- a/site_ansto/orhvps.c +++ b/site_ansto/orhvps.c @@ -682,15 +682,15 @@ static int ORHVPSSend(pEVDriver self, char *pCommand, char *pReply, int iLen) { rsp_len = CMDLEN; ORHV_SendReceive(self->pPrivate, cmd, cmd_len, rsp, &rsp_len); idx = 0; - for (i = 0; i < rsp_len; ++i) { - if ((rsp[i] < 32 || rsp[i] > 126) && idx < iLen - 3) { - snprintf(&pReply[idx], 3, "\\%02x", rsp[i]); - idx += 3; + for (i = 0; i < rsp_len && idx < iLen - 1; ++i) { + if (rsp[i] < 32 || rsp[i] > 126) { + idx+=sprintf(&pReply[idx], "%02Xh", rsp[i]); } else if (idx < iLen) pReply[idx++] = rsp[i]; } - pReply[idx] = '\0'; + if (idx < iLen) + pReply[idx++] = '\0'; return 1; } return -1; @@ -1017,7 +1017,7 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, k += (argv[i][j+2] - 'a' + 10); else if (argv[i][j+2] >= 'A' && argv[i][j+2] <= 'F') k += (argv[i][j+2] - 'A' + 10); - i += 2; + j += 2; } } else @@ -1032,15 +1032,15 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, rsp_len = CMDLEN; ORHV_SendReceive(priv, cmd, cmd_len, rsp, &rsp_len); idx = 0; - for (i = 0; i < rsp_len; ++i) { + for (i = 0; i < rsp_len && idx < CMDLEN - 1; ++i) { if (rsp[i] < 32 || rsp[i] > 126) { - snprintf(&cmd[idx], 3, "\\%02x", rsp[i]); - idx += 3; + idx+=sprintf(&cmd[idx], "%02Xh", rsp[i]); } else cmd[idx++] = rsp[i]; } - cmd[idx] = '\0'; + if (idx < CMDLEN) + cmd[idx++] = '\0'; SCWrite(pCon, cmd, eValue); return 1; }