From 39c986666f6c4622d3ad63f4890e4ffee985ce19 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 19 Jun 2015 16:00:17 -0700 Subject: [PATCH] make string_compare_guy better --- Tuprules.tup | 2 +- src/string_compare_guy.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Tuprules.tup b/Tuprules.tup index 7509a14..dcb7206 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -9,7 +9,7 @@ GOFLAGS += -g GOFLAGS += -O3 CFLAGS += -Wall -#CFLAGS += -Werror +CFLAGS += -Werror !nim = |> ^ Nim: %f -> %o^ nim c $(NIMFLAGS) -o:%o %f && rm -rf .nimcache |> !gccgo = |> ^ GCCGo: %f -> %o^ gccgo $(GOFLAGS) -o %o %f |> diff --git a/src/string_compare_guy.c b/src/string_compare_guy.c index fa6eb3c..f19760e 100644 --- a/src/string_compare_guy.c +++ b/src/string_compare_guy.c @@ -1,23 +1,21 @@ #include #include +#include #include // string_compare_guy compares the contents of the left hand side, length with the contents of the // right hand side, length and returns 1 if the right hand side (needle) is inside the left hand // side (haystack). static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) { - char* lnz = malloc(llength + 1); + char* lnz = alloca(llength + 1); memcpy(lnz, lhs, llength); lnz[llength] = 0; - char* rnz = malloc(rlength + 1); + char* rnz = alloca(rlength + 1); memcpy(rnz, rhs, rlength); rnz[rlength] = 0; - int result = strstr(lnz, rhs); - - free(lnz); - free(rnz); + int result = (intptr_t) strstr(lnz, rhs); return result; }