Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 62 additions & 22 deletions src/main/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

#include <glib.h>
#include <treekeyidx.h>

#include <osisxhtml.h>
#include <thmlxhtml.h>
Expand Down Expand Up @@ -725,7 +726,7 @@ CacheHeader(ModuleCache::CacheVerse &cVerse,
GLOBAL_OPS *ops, BackEnd *be)
{
int x = 0;
gchar heading[8];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of increasing the size of the buffer here, would it be better to change the uses of sprintf to snprintf (which takes a maximum number of characters to print)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like that:
sprintf(heading, "%d", x);
by :
csnprintf(heading, sizeof(heading), "%d", x);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be snprintf(heading, sizeof(heading), "%d", x); (without the c at the start) but yes that's the right idea. I think it needs done on lines 735 and 750.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the waring remains with snprintf:

/home/cyrille/Documents/github/xiphos/src/main/display.cc: In member function ‘virtual char GTKPrintChapDisp::display(sword::SWModule&)’:
/home/cyrille/Documents/github/xiphos/src/main/display.cc:2226:61: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 8 [-Wformat-truncation=]
 2226 |                         snprintf(heading, sizeof(heading), "%d", x);
      |                                                             ^~
/home/cyrille/Documents/github/xiphos/src/main/display.cc:2226:60: note: directive argument in the range [1, 2147483647]
 2226 |                         snprintf(heading, sizeof(heading), "%d", x);
      |                                                            ^~~~
/home/cyrille/Documents/github/xiphos/src/main/display.cc:2226:33: note: ‘snprintf’ output between 2 and 11 bytes into a destination of size 8
 2226 |                         snprintf(heading, sizeof(heading), "%d", x);
      |                         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I cannot see those warnings on my build. What command produces that output for you?

gchar heading[32];
const gchar *preverse;
SWBuf preverse2;
GString *text = g_string_new("");
Expand Down Expand Up @@ -954,6 +955,42 @@ GTKEntryDisp::displayByChapter(SWModule &imodule, int columns)
//
// general display of entries: commentary, genbook, lexdict
//
static void
_render_display_level(SWModule &imodule, unsigned long offset,
int max_level, int cur_level, SWBuf &combined)
{
TreeKeyIdx *treekey = (TreeKeyIdx *)imodule.getKey();
treekey->setOffset(offset);
imodule.getRawEntry(); // snap to entry

const char *raw = imodule.getRawEntry();
if (raw && *raw) {
if (combined.length() > 0)
combined += "<br/><hr/>";
combined += imodule.renderText().c_str();
}

if (cur_level < max_level && treekey->hasChildren()) {
treekey->firstChild();
unsigned long child_offset = treekey->getOffset();
bool has_next = true;
while (has_next) {
_render_display_level(imodule, child_offset,
max_level, cur_level + 1,
combined);
// reposition after recursion
treekey->setOffset(child_offset);
imodule.getRawEntry();
has_next = treekey->nextSibling() && !treekey->popError();
if (has_next)
child_offset = treekey->getOffset();
}
// restore to current node
treekey->setOffset(offset);
imodule.getRawEntry();
}
}

char
GTKEntryDisp::display(SWModule &imodule)
{
Expand Down Expand Up @@ -1075,28 +1112,31 @@ GTKEntryDisp::display(SWModule &imodule)
(modtype == PRAYERLIST_TYPE))
rework = g_string_new(strongs_or_morph
? block_render(imodule.getRawEntry())
: imodule.getRawEntry());
: imodule.getRawEntry());
else {
rework = g_string_new(strongs_or_morph
? block_render(imodule.renderText().c_str())
: imodule.renderText().c_str());
if (modtype == DICTIONARY_TYPE) {
char *f = (char *)imodule.getConfigEntry("Feature");
if (f && !strcmp(f, "DailyDevotion")) {
char *pretty;
char *month = backend->get_module_key();
char *day = strchr(month, '.');
if (day)
*(day++) = '\0';
else
day = (char *)"XX";
int idx_month = atoi(month) - 1;
pretty = gettext(month_names[idx_month]);
pretty = g_strdup_printf("<b>%s %s</b><br/>",
(pretty ? pretty : "--"),
day);
swbuf.append(pretty);
g_free(pretty);
// respect DisplayLevel for genbooks (BOOK_TYPE):
const char *dl_str = imodule.getConfigEntry("DisplayLevel");
int display_level = dl_str ? atoi(dl_str) : 1;
if (display_level <= 1) {
rework = g_string_new(strongs_or_morph
? block_render(imodule.renderText().c_str())
: imodule.renderText().c_str());
} else {
SWMgr *mgr = backend->get_mgr();
SWModule *mod = mgr->Modules[imodule.getName()];
TreeKeyIdx *treekey = dynamic_cast<TreeKeyIdx *>(mod->getKey());
if (!treekey) {
rework = g_string_new(imodule.renderText().c_str());
} else {
TreeKeyIdx saved = *treekey;
SWBuf combined = "";
_render_display_level(*mod, saved.getOffset(),
display_level, 1, combined);
treekey->setOffset(saved.getOffset());
mod->getRawEntry();
rework = g_string_new(strongs_or_morph
? block_render(combined.c_str())
: combined.c_str());
}
}
}
Expand Down
Loading