strncpy is trouble

This commit is contained in:
Vitor Santos Costa 2016-08-15 14:52:39 -05:00
parent 44262405df
commit 7b86e28e00

View File

@ -76,13 +76,13 @@ loop:
return Yap_unify(ARG1, ARG3) && Yap_unify(ARG2, MkStringTerm("")); return Yap_unify(ARG1, ARG3) && Yap_unify(ARG2, MkStringTerm(""));
} }
tmp = malloc((ss - f) + 1); tmp = malloc((ss - f) + 1);
strncpy(tmp, f, (ss)-f); int i;
for (i=0;i < (ss - f); i++) tmp[i] = ss[i];
tmp[i] = '\0';
if (!Yap_unify(ARG1, MkStringTerm(tmp))) { if (!Yap_unify(ARG1, MkStringTerm(tmp))) {
if (tmp != f)
free(tmp); free(tmp);
return false; return false;
} }
if (tmp != f)
free(tmp); free(tmp);
// without and with dot // without and with dot
if (!Yap_unify(ARG2, MkStringTerm(ss + 1))) if (!Yap_unify(ARG2, MkStringTerm(ss + 1)))
@ -95,7 +95,9 @@ loop:
Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(""))); Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom("")));
} }
tmp = malloc((ss - f) + 1); tmp = malloc((ss - f) + 1);
strncpy(tmp, f, (ss)-f); int i;
for (i=0;i < (ss - f); i++) tmp[i] = ss[i];
tmp[i] = '\0';
if (!Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(tmp)))) { if (!Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(tmp)))) {
if (tmp != f) if (tmp != f)
free(tmp); free(tmp);