Skip to content

Commit

Permalink
geanygendoc: Fix crash if trying to document an unknown type
Browse files Browse the repository at this point in the history
Fix crash if the tag to generate documentation for is of an unknown
type.  Also consolidate some code around this to validate parameters
just to be more defensive in case it sill actually happens.

Fixes geany#1362.
  • Loading branch information
b4n committed Jul 6, 2024
1 parent d8df495 commit 63cd681
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion geanygendoc/src/ggd-doc-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ ggd_doc_type_get_setting (const GgdDocType *doctype,
{
GgdDocSetting *setting = NULL;
GList *tmp;
gssize match_len = strlen (match);
gssize match_len;

g_return_val_if_fail (doctype != NULL, NULL);
g_return_val_if_fail (match != NULL, NULL);

match_len = (gssize) strlen (match);

for (tmp = doctype->settings; tmp && ! setting; tmp = g_list_next (tmp)) {
if (ggd_doc_setting_matches (tmp->data, match, match_len)) {
Expand Down Expand Up @@ -177,6 +180,7 @@ ggd_doc_type_resolve_setting (const GgdDocType *doctype,
gchar *child_match = NULL;

g_return_val_if_fail (doctype != NULL, NULL);
g_return_val_if_fail (match != NULL, NULL);

/*g_debug ("Resolving match \"%s\"...", child_match);*/
if (nth_child) (*nth_child) = 0;
Expand Down
17 changes: 10 additions & 7 deletions geanygendoc/src/ggd.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,25 @@ get_setting_from_tag (GgdDocType *doctype,
const TMTag *tag,
const TMTag **real_tag)
{
GgdDocSetting *setting;
GgdDocSetting *setting = NULL;
gchar *hierarchy;
gint nth_child;
GPtrArray *tag_array = doc->tm_file->tags_array;
GeanyFiletypeID geany_ft = FILETYPE_ID (doc->file_type);

hierarchy = ggd_tag_resolve_type_hierarchy (tag_array, geany_ft, tag);
/*g_debug ("type hierarchy for tag %s is: %s", tag->name, hierarchy);*/
setting = ggd_doc_type_resolve_setting (doctype, hierarchy, &nth_child);
*real_tag = tag;
if (setting) {
for (; nth_child > 0; nth_child--) {
*real_tag = ggd_tag_find_parent (tag_array, geany_ft, *real_tag);
if (hierarchy) {
gint nth_child;

setting = ggd_doc_type_resolve_setting (doctype, hierarchy, &nth_child);
if (setting) {
for (; nth_child > 0; nth_child--) {
*real_tag = ggd_tag_find_parent (tag_array, geany_ft, *real_tag);
}
}
g_free (hierarchy);
}
g_free (hierarchy);

return setting;
}
Expand Down

0 comments on commit 63cd681

Please sign in to comment.