GNOME Bugzilla – Bug 737222
Calculator search provider spams journal with runtime warnings
Last modified: 2016-01-30 17:43:39 UTC
search_provider_get_result_identifier: runtime check failed: ((_tmp10__length1 == 0) || (_tmp11__length1 == 1))
This warning is generated by https://git.gnome.org/browse/gnome-calculator/tree/search-provider/search-provider.vala#n43 with: private static string[] get_result_identifier (string[] terms) ensures (result.length == 0 || result.length == 1)
Yeah, the problem is, it makes absolutely no sense that we would have more than one search result (the answer), or fewer than zero, so some debugging is required.
I can clearly see the C code, that is being generated is wrong. In both cases, the condition is always going to fail. (Does that mean, there's a bug in Vala??) e.g. When the result has only one element, the code is as follwoing, result = _tmp5_; _tmp6_ = result; _tmp6__length1 = -1; _tmp7_ = result; _tmp7__length1 = -1; g_warn_if_fail ((_tmp6__length1 == 0) || (_tmp7__length1 == 1)); return result; and, when result is zero element string, the code is as follwoing, gchar** _tmp8_ = NULL; gchar** _tmp9_ = NULL; gint _tmp9__length1 = 0; gchar** _tmp10_ = NULL; gint _tmp10__length1 = 0; gchar** _tmp11_ = NULL; gint _tmp11__length1 = 0; _tmp8_ = g_new0 (gchar*, 0 + 1); _tmp9_ = _tmp8_; _tmp9__length1 = 0; if (result_length1) { *result_length1 = _tmp9__length1; } result = _tmp9_; _tmp10_ = result; _tmp10__length1 = -1; _tmp11_ = result; _tmp11__length1 = -1; g_warn_if_fail ((_tmp10__length1 == 0) || (_tmp11__length1 == 1));
_tmp10__length1 = -1; ... _tmp11__length1 = -1; g_warn_if_fail ((_tmp10__length1 == 0) || (_tmp11__length1 == 1)); OK, good catch. So this is indeed looks like a Vala bug. I guess it should handle the zero-length array properly, or else give an error. Let's see what the Vala developers have to say.... I guess "don't do that" is probably a valid response, though I'm not sure how else to indicate no results.
Created attachment 292126 [details] [review] Set array lengths for result variable Fixes bug 737222
Created attachment 292127 [details] [review] Improve pre/postcondition messages Additional patch to make pre/postconditions more readable, same as assert()
Pre and post conditions are very broken atm for && or || checks. Planning to fix them. So when doing complex checks, be aware to check your C code. Sorry for the inconvenience. Will review the patches asap, thanks.
Review of attachment 292126 [details] [review]: Thanks, however it breaks code that previously worked by assuming that returned arrays always have a length variable: [CCode (array_length = false, array_null_terminated = true)] private static string[] test () ensures (result[0] == "foo") { return new string[]{ "bar" }; } void main () { test(); }
Review of attachment 292127 [details] [review]: Good one thanks!
Created attachment 292203 [details] [review] Added check if result has array length Ok, this should work now. I added a test for this case as well.
commit f403b05730a012563c75b56d7475d1e8240a7656 Author: Simon Werbeck <simon.werbeck@gmail.com> Date: Tue Nov 25 02:23:17 2014 +0100 Set array lengths for result variable These where missing when generating postconditions Fixes bug 737222 Can be improved but it's better than nothing for now, thanks a lot. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
*** Bug 698336 has been marked as a duplicate of this bug. ***