Skip to content
Browse files

Do not use strtok(). Change it by g_strsplit() for thread safeness

  • Loading branch information...
1 parent 8bcec60 commit 18d4d6b8cb23a0c43782d244d0a828cc13145cd3 @jcsogo jcsogo committed Apr 9, 2012
Showing with 41 additions and 31 deletions.
  1. +39 −31 src/libs/keywords.c
  2. +2 −0 src/libs/tools/hinter.c
View
70 src/libs/keywords.c
@@ -130,41 +130,49 @@ void gui_init(dt_lib_module_t *self)
int level = 0;
char *value;
GtkTreeIter current,iter;
- char *pch = strtok((char *)sqlite3_column_text(stmt, 0),"|");
- while (pch != NULL)
+ char **pch = g_strsplit((char *)sqlite3_column_text(stmt, 0),"|", -1);
+
+ if (pch != NULL)
{
- gboolean found=FALSE;
- int children = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),level>0?&current:NULL);
- /* find child with name, if not found create and continue */
- for (int k=0;k<children;k++)
- {
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, level>0?&current:NULL, k))
- {
- gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, 0, &value, -1);
+ int j = 0;
+ while (pch[j] != NULL)
+ {
+ gboolean found=FALSE;
+ int children = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),level>0?&current:NULL);
+ /* find child with name, if not found create and continue */
+ for (int k=0;k<children;k++)
+ {
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, level>0?&current:NULL, k))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, 0, &value, -1);
- if (strcmp(value, pch)==0)
- {
- current = iter;
- found = TRUE;
- break;
- }
- }
- }
-
- /* lets add new keyword and assign current */
- if (!found)
- {
- gtk_tree_store_insert(store, &iter, level>0?&current:NULL,0);
- gtk_tree_store_set(store, &iter, 0, pch, -1);
- current = iter;
- }
-
- level++;
- pch = strtok(NULL, "|");
- }
+ if (strcmp(value, pch[j])==0)
+ {
+ current = iter;
+ found = TRUE;
+ j++;
+ break;
+ }
+ }
+ }
+
+
+ /* lets add new keyword and assign current */
+ if (!found)
+ {
+ gtk_tree_store_insert(store, &iter, level>0?&current:NULL,0);
+ gtk_tree_store_set(store, &iter, 0, pch[j], -1);
+ current = iter;
+ }
+
+ level++;
+ j++;
+ }
+
+ g_strfreev(pch);
+ }
}
-
}
/* add the treeview to show hirarchy tags*/
View
2 src/libs/tools/hinter.c
@@ -96,6 +96,8 @@ void _lib_hinter_set_message(dt_lib_module_t *self, const char *message)
int c = 0;
char *str = g_strdup(message);
+ /* FIXME: If this code is re-enabled, strtok() should be changed
+ * for g_strsplit() for thread-safeness */
char *s = strtok(str," ");
gchar *markup=NULL;

0 comments on commit 18d4d6b

Please sign in to comment.
Something went wrong with that request. Please try again.