From d16aa3c0a79aa30c9b8c5b351b0f327495e85517 Mon Sep 17 00:00:00 2001 From: Xavier Roumegue Date: Tue, 9 Mar 2021 20:46:13 +0100 Subject: [PATCH] [Decoder/Utils] Remove last empty label while enumerating labels from file While parsing the labels file, a label per line is expected. g_strsplit(file_contents, '\n', -1) is used to parse the file and returns the label as a string vector. The last '\n' in the file introduces an additional empty element, as the delimiter involves 2 elements. Hence, the patch is removing the last trailing '\n' to avoid this additional dummy element in the labels list. Signed-off-by: Xavier Roumegue --- ext/nnstreamer/tensor_decoder/tensordecutil.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/nnstreamer/tensor_decoder/tensordecutil.c b/ext/nnstreamer/tensor_decoder/tensordecutil.c index 76fa4f3..ef6fc30 100644 --- a/ext/nnstreamer/tensor_decoder/tensordecutil.c +++ b/ext/nnstreamer/tensor_decoder/tensordecutil.c @@ -38,6 +38,10 @@ loadImageLabels (const char *label_path, imglabel_t * l) g_clear_error (&err); return; } + len = strlen (contents); + + if (contents[len - 1] == '\n') + contents[len - 1] = '\0'; _labels = g_strsplit (contents, "\n", -1); l->total_labels = g_strv_length (_labels); -- 2.7.4