From 66032c95f24a84e287102af7d65a55a839c23fe2 Mon Sep 17 00:00:00 2001 From: fef Date: Fri, 16 Jul 2021 14:43:02 +0200 Subject: [PATCH] string: sanitize nstrcmp return value on error --- src/string/nstrcmp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/string/nstrcmp.c b/src/string/nstrcmp.c index 89ceb55..cfd97d3 100644 --- a/src/string/nstrcmp.c +++ b/src/string/nstrcmp.c @@ -11,13 +11,21 @@ int nstrcmp(const string *s1, const string *s2, error *err) { + /* + * Return values are always undefined if an error was yeeted so it's not + * strictly necessary to return a correct(ish) result here, but the + * philosophy of libneo is to always behave in a way that is the least + * harmful. + */ if (s1 == nil) { yeet(err, EFAULT, "First string is nil"); - return 0; + if (s2 == nil) + return 0; + return -1; } if (s2 == nil) { yeet(err, EFAULT, "Second string is nil"); - return 0; + return 1; } int ret;