> @codebrainz the file_name can be null for unnamed docs, or am I wrong ?

Yeah, I thought it was always either the filename or "untitled" (the API docs 
don't mention it can be `NULL`), but rather what I was thinking of was usage of 
`DOC_FILENAME()` macro, which gives "untitled" if `file_name` is `NULL`. This 
macro should probably be used in this PR, else navqueue won't work for files 
that aren't saved yet (or is this an existing bug?).

>  NULL doc is only prevented from something hidden in the context, in this 
> case UI sensitivity.

That's just using different words to say "code". There's a contract established 
in the code that says whether a document can be `NULL` or not at a particular 
point in a program (for example, upon entrance to a function). If that contract 
is violated, a programming error has been inserted into the code, and this is 
exactly what an assert is meant to catch. The contract is local to this 
particular function, it's irrelevant where the programming error came from 
ultimately, the assert is just meant to catch the error quickly in this one 
location.

The error should never reach the user in a release build because any PR 
changing behaviour needs to check all the places affected (ex. something 
messing with action sensitively needs to test all of the features that rely on 
it). IMO, it's bad style to just make the program behave wrongly or carry on 
like nothing is wrong and crash later, far away from the error.

> Right, but so does simply dereferencing doc in the very next line.

If you're lucky, that will have the same effect as an assert (except silently, 
without any diagnostic info, like file/line/expression) and just crash. If 
you're unlucky, it will do anything else. What happens is completely undefined 
behaviour.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/1537#issuecomment-315540374

Reply via email to