Permalink
Browse files

Made Pire::Run() accept (NULL, NULL) pointer pair.

  • Loading branch information...
1 parent 012bedf commit 63c09b364c3a6835ea33a43af868fc210f166945 Dmitry Prokoptsev committed Nov 18, 2013
Showing with 26 additions and 0 deletions.
  1. +16 −0 pire/platform.h
  2. +3 −0 pire/run.h
  3. +7 −0 tests/pire_ut.cpp
View
@@ -42,6 +42,22 @@
#define PIRE_HOT_FUNCTION
#endif
+#ifndef PIRE_LIKELY
+#ifdef __GNUC__
+#define PIRE_LIKELY(x) (__builtin_expect((x), 1))
+#else
+#define PIRE_LIKELY(x) (x)
+#endif
+#endif
+
+#ifndef PIRE_UNLIKELY
+#ifdef __GNUC__
+#define PIRE_UNLIKELY(x) (__builtin_expect((x), 0))
+#else
+#define PIRE_UNLIKELY(x) (x)
+#endif
+#endif
+
#ifdef _MSC_VER
#include <stdio.h>
#include <stdarg.h>
View
@@ -114,6 +114,9 @@ namespace Impl {
YASSERT(size <= sizeof(size_t));
YASSERT(pos + size <= sizeof(size_t));
+ if (PIRE_UNLIKELY(size == 0))
+ return Continue;
+
#ifdef PIRE_ENABLE_VALGRIND_SAFE
const char* ptr = (const char*) p + pos;
for (; size--; ++ptr) {
View
@@ -727,4 +727,11 @@ SIMPLE_UNIT_TEST(EmptyScanner)
BasicTestEmptySaveLoadMmap<Pire::SlowScanner>();
}
+SIMPLE_UNIT_TEST(NullPointer)
+{
+ const char* null = 0;
+ Pire::Scanner sc = Pire::Fsm().Compile<Pire::Scanner>();
+ Pire::Runner(sc).Begin().Run(null, null).End();
+}
+
}

0 comments on commit 63c09b3

Please sign in to comment.