diff --git a/src/sink/snk_categories.c b/src/sink/snk_categories.c index a201bf5..f2ed1e4 100644 --- a/src/sink/snk_categories.c +++ b/src/sink/snk_categories.c @@ -336,12 +336,14 @@ void snk_categories_process_format_text_json(snk_categories_obj * obj) { unsigned int iChannel; + int tmpBufferSize; obj->buffer[0] = 0x00; + tmpBufferSize = 0; - sprintf(obj->buffer,"%s{\n",obj->buffer); - sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); - sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, "{\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " \"timeStamp\": %llu,\n", obj->in->timeStamp); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " \"src\": [\n"); for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { @@ -349,19 +351,19 @@ case 0x01: - sprintf(obj->buffer,"%s { \"category\": \"speech\" }",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " { \"category\": \"speech\" }"); break; case 0x00: - sprintf(obj->buffer,"%s { \"category\": \"nonspeech\" }",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " { \"category\": \"nonspeech\" }"); break; default: - sprintf(obj->buffer,"%s { \"category\": \"undefined\" }",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " { \"category\": \"undefined\" }"); break; @@ -369,16 +371,16 @@ if (iChannel != (obj->nChannels - 1)) { - sprintf(obj->buffer,"%s,",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, ","); } - sprintf(obj->buffer,"%s\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, "\n"); } - - sprintf(obj->buffer,"%s ]\n",obj->buffer); - sprintf(obj->buffer,"%s}\n",obj->buffer); + + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " ]\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"}\n"); obj->bufferSize = strlen(obj->buffer); diff --git a/src/sink/snk_pots.c b/src/sink/snk_pots.c index 8445599..d4710bd 100644 --- a/src/sink/snk_pots.c +++ b/src/sink/snk_pots.c @@ -352,30 +352,32 @@ void snk_pots_process_format_text_json(snk_pots_obj * obj) { unsigned int iPot; + int tmpBufferSize; obj->buffer[0] = 0x00; + tmpBufferSize = 0; - sprintf(obj->buffer,"%s{\n",obj->buffer); - sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); - sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"{\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," \"timeStamp\": %llu,\n",obj->in->timeStamp); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," \"src\": [\n"); for (iPot = 0; iPot < obj->nPots; iPot++) { - sprintf(obj->buffer,"%s { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }", obj->buffer, + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," { \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"E\": %1.3f }", obj->in->pots->array[iPot*4+0], obj->in->pots->array[iPot*4+1], obj->in->pots->array[iPot*4+2], obj->in->pots->array[iPot*4+3]); if (iPot != (obj->nPots - 1)) { - sprintf(obj->buffer,"%s,",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,","); } - sprintf(obj->buffer,"%s\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"\n"); } - sprintf(obj->buffer,"%s ]\n",obj->buffer); - sprintf(obj->buffer,"%s}\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," ]\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"}\n"); obj->bufferSize = strlen(obj->buffer); diff --git a/src/sink/snk_tracks.c b/src/sink/snk_tracks.c index b92eb46..bb1742c 100644 --- a/src/sink/snk_tracks.c +++ b/src/sink/snk_tracks.c @@ -341,17 +341,18 @@ void snk_tracks_process_format_text_json(snk_tracks_obj * obj) { unsigned int iTrack; + int tmpBufferSize; obj->buffer[0] = 0x00; + tmpBufferSize = 0; - sprintf(obj->buffer,"%s{\n",obj->buffer); - sprintf(obj->buffer,"%s \"timeStamp\": %llu,\n",obj->buffer,obj->in->timeStamp); - sprintf(obj->buffer,"%s \"src\": [\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"{\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," \"timeStamp\": %llu,\n",obj->in->timeStamp); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," \"src\": [\n"); for (iTrack = 0; iTrack < obj->nTracks; iTrack++) { - sprintf(obj->buffer,"%s { \"id\": %llu, \"tag\": \"%s\", \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"activity\": %1.3f }", - obj->buffer, + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize," { \"id\": %llu, \"tag\": \"%s\", \"x\": %1.3f, \"y\": %1.3f, \"z\": %1.3f, \"activity\": %1.3f }", obj->in->tracks->ids[iTrack], obj->in->tracks->tags[iTrack], obj->in->tracks->array[iTrack*3+0], @@ -361,16 +362,16 @@ if (iTrack != (obj->nTracks - 1)) { - sprintf(obj->buffer,"%s,",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, ","); } - sprintf(obj->buffer,"%s\n",obj->buffer); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, "\n"); } - - sprintf(obj->buffer,"%s ]\n",obj->buffer); - sprintf(obj->buffer,"%s}\n",obj->buffer); + + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize, " ]\n"); + tmpBufferSize += sprintf(obj->buffer + tmpBufferSize,"}\n"); obj->bufferSize = strlen(obj->buffer);