[gnome-builder] fuzzy: check bounds better in our example



commit 9043baab007a84f77a77420eff2e553c3746bff7
Author: Christian Hergert <christian hergert me>
Date:   Sat Oct 3 15:35:09 2015 -0700

    fuzzy: check bounds better in our example

 tests/test-fuzzy.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/tests/test-fuzzy.c b/tests/test-fuzzy.c
index b8f078e..cf96e88 100644
--- a/tests/test-fuzzy.c
+++ b/tests/test-fuzzy.c
@@ -1,11 +1,14 @@
 #include <fuzzy.h>
 #include <ide-line-reader.h>
+#include <stdlib.h>
+#include <string.h>
 
 int
 main (int argc,
       char *argv[])
 {
   IdeLineReader reader;
+  const gchar *param;
   Fuzzy *fuzzy;
   GArray *ar;
   gchar *contents;
@@ -40,7 +43,21 @@ main (int argc,
 
   g_free (contents);
 
-  ar = fuzzy_match (fuzzy, argv[2], 0);
+  if (!g_utf8_validate (argv[2], -1, NULL))
+    {
+      g_critical ("Invalid UTF-8 discovered, aborting.");
+      return EXIT_FAILURE;
+    }
+
+  if (strlen (argv[2]) > 256)
+    {
+      g_critical ("Only supports searching of up to 256 characters.");
+      return EXIT_FAILURE;
+    }
+
+  param = (const gchar *)argv[2];
+
+  ar = fuzzy_match (fuzzy, param, 0);
 
   for (guint i = 0; i < ar->len; i++)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]