Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sprintf usage in format json functions #293

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/sink/snk_categories.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,49 +336,51 @@
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++) {

switch(obj->in->categories->array[iChannel]) {

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;

}

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);

Expand Down
18 changes: 10 additions & 8 deletions src/sink/snk_pots.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 11 additions & 10 deletions src/sink/snk_tracks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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);

Expand Down