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 624287 - Question about assertion in gtk_source_language_manager_guess_language.
Question about assertion in gtk_source_language_manager_guess_language.
Status: RESOLVED NOTABUG
Product: gtksourceview
Classification: Platform
Component: Syntax files
2.11.x
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-13 22:39 UTC by Krzesimir Nowak
Modified: 2010-07-16 11:20 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Krzesimir Nowak 2010-07-13 22:39:23 UTC
In the function mentioned in title there is an assertion:
g_return_val_if_fail ((filename == NULL || *filename != 0) &&
                  (content_type == NULL || *content_type != 0), NULL);

Shouldn't it be rewritten to allow passing empty strings? With current assertion the call below fails:

lang = gtk_source_language_manager_guess_language(lm, "test.cpp", "");

The current assertion now stated that if any passed pointer (filename or content_type) is not NULL then it cannot be empty, while it should (in my opinion of course) be tolerable to have nonNULL empty strings - they would be treated like NULL strings.

Just asking because in C++ bindings a c_str() is passed to C function - in case of empty Glib::ustring (or std::string) c_str() returns "" instead of NULL. If above assertion is correct, then I'll have to add two overloads for both NULL parameters.

Proposed rewrite of assertion could be:
g_return_val_if_fail ((filename != NULL && *filename != 0) ||
                  (content_type != NULL && *content_type != 0), NULL);

Such assertion will fail when:
1. Both parameters are NULL.
2. Both parameters are empty strings ("").
3. One of parameter is empty string ("") and another is NULL.
and will pass when at least one parameter is not NULL and not empty.
Comment 1 Krzesimir Nowak 2010-07-16 11:20:49 UTC
The response is in bug 624284.