Formatting Dive tags string
djeBrest at gmail.com
Wed Apr 4 09:04:35 PDT 2018
Here is the pull request :)
2018-04-04 14:35 GMT+02:00 Lubomir I. Ivanov <neolit123 at gmail.com>:
> On 4 April 2018 at 14:27, Lubomir I. Ivanov <neolit123 at gmail.com> wrote:
> > On 4 April 2018 at 12:36, Jérémie Guichard <djeBrest at gmail.com> wrote:
> >> Hello everybody,
> >> While reviewing this change adding display for Tags in dive list view
> >> (https://github.com/Subsurface-divelog/subsurface/pull/1184), Lubomir
> >> Dirk raised a concern regarding tag text that can exceed inputted buffer
> >> size. Issue comes from implementation/signature of taglist_get_tagstring
> >> function
> >> https://github.com/Subsurface-divelog/subsurface/blob/
> >> Certainly no current user has been using enough tags to actually
> >> problems with this but who knows...
> >> Staring from their input and doing some code digging, here is a short
> >> overview of my findings and proposals.
> >> taglist_get_tagstring function currently prints as many full tags as
> >> be fitted in the inputted buffer and returns the length of the printed
> >> string. This approach raise several issues when it comes to long tag
> >> a) It is not possible to know from the returned information if all tags
> >> were actually printed.
> >> b) When a user would (in the UI) add a long tag list, the full tag
> list is
> >> (at first) indeed saved. Then, only text returned by
> >> gets displayed. This causes later edits of the tags to delete tags that
> >> not displayed, not good...
> >> c) Looking at DiveObjectHelper class the function is used with 256
> >> size so issue would become more visible if DiveObjectHelper::tags was
> >> actually used. It seems this method is not used yet (neither in Desktop
> >> in Mobile app) but I may be wrong, please point me to its usage if you
> >> one...
> >> Lubomir mentioned he could look into this 'issue' but did not have much
> >> time, since I do have some on my side I can look into this change. I do
> >> prefer to consult the community before doing it though. Here are the
> >> different solutions that came to my mind:
> >> 1) Add a output parameter to last printed struct tag_entry* in the
> list to
> >> the current taglist_get_tagstring allowing callers to iterate when
> >> (not my favorite)
> >> 2) It seems strange for a UI specific function to be part of dive.h/.c
> >> would rather move this functionality to 'Qt level' say in qthelper.h/.c
> >> other better location if one of you have a better proposal) and
> implement it
> >> using QStrings (avoiding the pre-allocated buffer issue). This is
> >> what is done for get_gas_string for example. It is my preferred proposal
> >> since all usage I could find of taglist_get_tagstring are in Qt code and
> >> this function is purely UI related code...
> >> I do have other topics to discuss with you guys but I'll send separate
> >> emails not to mix things up.
> > the function is kind of part of the C backend and we probably should
> > write it in C.
> > posted some comments in the issue thread at github about `
> > taglist_get_tagstring` as i saw this ML thread just now.
> copy paste from here:
> the approach for taglist_get_tagstring() would be:
> - make taglist_get_tagstring() accept a single argument (only the
> list, without buffer ptr and size)
> - go through the tags and calculate required size to malloc() (also
> consider ', ')
> - malloc() a char * buffer once
> - go through the tags again and copy the tags over the buffer while adding
> ', '
> - make taglist_get_tagstring() return NULL / buffer instead of int.
> - use this buffer to create QString by the callers of
> taglist_get_tagstring() and free this buffer too:
> (as Berthold already pointed out)
> char *str_list = taglist_get_tagstring(some_tag_list);
> QSting ret(str_list);
> return ret;
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the subsurface