Commit 1956e033 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Fixed minor bug: add check buffer_length > 0


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1051 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 3f988da9
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.87 2008-04-08 07:57:23 mtheo Exp $
* $Id: nmxp.c,v 1.88 2008-04-09 07:57:01 mtheo Exp $
*
*/
......@@ -78,41 +78,49 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag) {
int ret;
int ret = NMXP_SOCKET_OK;
int32_t buffer_length = 16 + (4 * channelList->number);
char *buffer = NMXP_MEM_MALLOC(buffer_length);
char *buffer = NULL;
int32_t app, i, disp;
disp=0;
if(buffer_length > 0) {
buffer = NMXP_MEM_MALLOC(buffer_length);
app = htonl(channelList->number);
memcpy(&buffer[disp], &app, 4);
disp+=4;
disp=0;
for(i=0; i < channelList->number; i++) {
app = htonl(channelList->channel[i].key);
app = htonl(channelList->number);
memcpy(&buffer[disp], &app, 4);
disp+=4;
for(i=0; i < channelList->number; i++) {
app = htonl(channelList->channel[i].key);
memcpy(&buffer[disp], &app, 4);
disp+=4;
}
app = htonl(shortTermCompletion);
memcpy(&buffer[disp], &app, 4);
disp+=4;
}
app = htonl(shortTermCompletion);
memcpy(&buffer[disp], &app, 4);
disp+=4;
app = htonl(out_format);
memcpy(&buffer[disp], &app, 4);
disp+=4;
app = htonl(out_format);
memcpy(&buffer[disp], &app, 4);
disp+=4;
app = htonl(buffer_flag);
memcpy(&buffer[disp], &app, 4);
disp+=4;
app = htonl(buffer_flag);
memcpy(&buffer[disp], &app, 4);
disp+=4;
ret = nmxp_sendMessage(isock, NMXP_MSG_ADDTIMESERIESCHANNELS, buffer, buffer_length);
ret = nmxp_sendMessage(isock, NMXP_MSG_ADDTIMESERIESCHANNELS, buffer, buffer_length);
if(buffer) {
NMXP_MEM_FREE(buffer);
buffer = NULL;
if(buffer) {
NMXP_MEM_FREE(buffer);
buffer = NULL;
}
} else {
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "nmxp_sendAddTimeSeriesChannel_raw() buffer length = %d.\n", buffer_length);
}
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment