Skip to content

Commit

Permalink
Merge Richard Cohen's 'guard-against-null-dereference' into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Mar 10, 2023
2 parents 58146da + 329a2f7 commit 35dd8db
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bindings/guile/gnc-kvp-guile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ gnc_kvp_value_ptr_to_scm(KvpValue* val)
case KvpValue::Type::GUID:
{
auto tempguid = val->get<GncGUID*>();
return gnc_guid2scm(*tempguid);
return tempguid ? gnc_guid2scm(*tempguid) : SCM_BOOL_F;
}
break;
case KvpValue::Type::FRAME:
Expand All @@ -133,7 +133,7 @@ gnc_kvp_value_ptr_to_scm(KvpValue* val)
auto val_scm { gnc_kvp_value_ptr_to_scm (iter.second) };
return scm_acons (key_scm, val_scm, rv);
};
return scm_reverse (std::accumulate (frame->begin(), frame->end(), SCM_EOL, acc));
return frame ? scm_reverse (std::accumulate (frame->begin(), frame->end(), SCM_EOL, acc)) : SCM_BOOL_F;
}
break;
case KvpValue::Type::GLIST:
Expand Down
4 changes: 3 additions & 1 deletion gnucash/gnome-search/search-core-type.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ editable_enters (GNCSearchCoreType *fe)
void
gnc_search_core_register_type (const char *type_name, GNCSearchCoreNew fcn)
{
g_return_if_fail (type_name || *type_name || fcn);
g_return_if_fail (type_name);
g_return_if_fail (*type_name);
g_return_if_fail (fcn);
g_return_if_fail (typeTable);

g_hash_table_insert (typeTable, (char *) type_name, (gpointer) fcn);
Expand Down
6 changes: 5 additions & 1 deletion gnucash/gnome/gnc-plugin-page-owner-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,11 @@ static int build_owner_report (GncOwner *owner, Account *acc)
args = scm_cons (SCM_BOOL_F, args);
}

arg = SWIG_NewPointerObj(owner, SWIG_TypeQuery("_p__gncOwner"), 0);
swig_type_info * qtype = SWIG_TypeQuery("_p__gncOwner");
g_return_val_if_fail (qtype, -1);

arg = SWIG_NewPointerObj(owner, qtype, 0);

g_return_val_if_fail (arg != SCM_UNDEFINED, -1);
args = scm_cons (arg, args);

Expand Down
3 changes: 3 additions & 0 deletions gnucash/report/gnc-report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ gnc_get_optiondb_from_dispatcher(SCM dispatcher)
else
c_ptr = reinterpret_cast<void*>(SCM_CELL_WORD_1(smob));
}
else
return nullptr;

auto u_ptr{static_cast<std::unique_ptr<GncOptionDB>*>(c_ptr)};
return u_ptr->get();
}
Expand Down
7 changes: 5 additions & 2 deletions libgnucash/app-utils/calculation/expression_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,11 @@ parse_string (var_store_ptr value, const char *string, parser_env_ptr pe)
var_store_ptr val;

val = pop (pe);
pe->negate_numeric (val->value);
push (val, pe);
if (val)
{
pe->negate_numeric (val->value);
push (val, pe);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions libgnucash/engine/gnc-date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
/* today's date */
gnc_time (&secs);
now = gnc_localtime (&secs);
if (!now)
return FALSE;
now_day = now->tm_mday;
now_month = now->tm_mon + 1;
now_year = now->tm_year + 1900;
Expand Down
3 changes: 2 additions & 1 deletion libgnucash/engine/qofquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,8 @@ qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
break;
}

retval->search_for = search_for;
if (retval)
retval->search_for = search_for;
return retval;
}

Expand Down

0 comments on commit 35dd8db

Please sign in to comment.