summaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-07-15 00:37:47 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-07-26 20:00:58 -0700
commit931cf1469a8036f72ab12d792ec820c2fb81cc62 (patch)
treec6dffa471270219f330bcb6e2513fdae50918cbd /match.c
parent017bbd0c5661be48c289575ca543f9e31b499b88 (diff)
Skip calculate_score for long candidates
Diffstat (limited to 'match.c')
-rw-r--r--match.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/match.c b/match.c
index 1c4c54b..78982d0 100644
--- a/match.c
+++ b/match.c
@@ -31,9 +31,21 @@ void mat_print(int *mat, int n, int m){
typedef int score_t;
double calculate_score(const char *needle, const char *haystack){
+ if(!*haystack || !*needle)
+ return SCORE_MIN;
+
int n = strlen(needle);
int m = strlen(haystack);
+ if(m > 1024){
+ /*
+ * Unreasonably large candidate: return no score
+ * If it is a valid match it will still be returned, it will
+ * just be ranked below any reasonably sized candidates
+ */
+ return 0;
+ }
+
int bow[m];
int D[n][m], M[n][m];
bzero(D, sizeof(D));