After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 737222 - Calculator search provider spams journal with runtime warnings
Calculator search provider spams journal with runtime warnings
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.26.x
Other Linux
: Normal minor
: ---
Assigned To: Vala maintainers
Vala maintainers
: 698336 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-09-23 21:58 UTC by Michael Catanzaro
Modified: 2016-01-30 17:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Set array lengths for result variable (1.98 KB, patch)
2014-12-04 14:55 UTC, Simon Werbeck
needs-work Details | Review
Improve pre/postcondition messages (3.93 KB, patch)
2014-12-04 14:57 UTC, Simon Werbeck
accepted-commit_now Details | Review
Added check if result has array length (2.25 KB, patch)
2014-12-05 16:48 UTC, Simon Werbeck
none Details | Review

Description Michael Catanzaro 2014-09-23 21:58:49 UTC
search_provider_get_result_identifier: runtime check failed: ((_tmp10__length1 == 0) || (_tmp11__length1 == 1))
Comment 1 Christian Stadelmann 2014-09-30 00:11:59 UTC
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)
Comment 2 Michael Catanzaro 2014-09-30 03:14:09 UTC
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.
Comment 3 PioneerAxon 2014-09-30 03:33:54 UTC
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));
Comment 4 Michael Catanzaro 2014-09-30 03:56:56 UTC
                _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.
Comment 5 Simon Werbeck 2014-12-04 14:55:08 UTC
Created attachment 292126 [details] [review]
Set array lengths for result variable

Fixes bug 737222
Comment 6 Simon Werbeck 2014-12-04 14:57:24 UTC
Created attachment 292127 [details] [review]
Improve pre/postcondition messages

Additional patch to make pre/postconditions more readable, same as assert()
Comment 7 Luca Bruno 2014-12-04 15:09:20 UTC
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.
Comment 8 Luca Bruno 2014-12-05 15:40:12 UTC
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();
}
Comment 9 Luca Bruno 2014-12-05 15:40:41 UTC
Review of attachment 292127 [details] [review]:

Good one thanks!
Comment 10 Simon Werbeck 2014-12-05 16:48:23 UTC
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.
Comment 11 Luca Bruno 2014-12-05 16:57:26 UTC
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.
Comment 12 Jürg Billeter 2016-01-30 17:43:39 UTC
*** Bug 698336 has been marked as a duplicate of this bug. ***