From 0220c850a043af46385d6cd6cf4ffa9ceb5696e3 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 16:40:01 +0200 Subject: [PATCH 01/28] Enable -pedantic and -std=c++11 by default Reviewed-by: dogma --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4f4c99fe2..6e878945c 100644 --- a/configure.ac +++ b/configure.ac @@ -665,7 +665,7 @@ dnl ----------- dnl if eval "test x$GCC = xyes"; then - CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-rtti -fno-exceptions" + CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-rtti -fno-exceptions -pedantic -std=c++11" fi AC_SUBST(BASE_CUR_WORKING_DIR) From 1e2f9219883452ef7da37c3c984b3e3d2939656b Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 16:40:09 +0200 Subject: [PATCH 02/28] Fix pedantic warnings Reviewed-by: dogma --- dpi/downloads.cc | 6 +++--- dw/fltkcomplexbutton.cc | 2 ++ dw/fltkimgbuf.cc | 6 ++++-- dw/fltkplatform.cc | 2 +- dw/fltkui.cc | 2 +- dw/layout.cc | 8 +++++--- dw/style.cc | 14 ++++++++++++++ dw/table.cc | 1 + dw/textblock.cc | 33 +++++++++++++++++++++++++-------- dw/textblock.hh | 2 +- dw/textblock_iterator.cc | 5 +++-- dw/textblock_linebreaking.cc | 6 ++++-- src/dialog.cc | 2 +- src/form.cc | 3 +-- src/gif.c | 8 ++++---- src/html.cc | 1 + src/menu.cc | 4 ++-- src/uicmd.cc | 4 ++-- 18 files changed, 75 insertions(+), 34 deletions(-) diff --git a/dpi/downloads.cc b/dpi/downloads.cc index 90f7b76d3..ee805de92 100644 --- a/dpi/downloads.cc +++ b/dpi/downloads.cc @@ -679,11 +679,11 @@ static void secs2timestr(int et, char *str) eh = et / 3600; em = (et % 3600) / 60; es = et % 60; if (eh == 0) { if (em == 0) - snprintf(str, 8, "%ds", es); + snprintf(str, 16, "%ds", es); else - snprintf(str, 8, "%dm%ds", em, es); + snprintf(str, 16, "%dm%ds", em, es); } else { - snprintf(str, 8, "%dh%dm", eh, em); + snprintf(str, 16, "%dh%dm", eh, em); } } diff --git a/dw/fltkcomplexbutton.cc b/dw/fltkcomplexbutton.cc index 76af37133..e287b6897 100644 --- a/dw/fltkcomplexbutton.cc +++ b/dw/fltkcomplexbutton.cc @@ -63,6 +63,7 @@ int ComplexButton::handle(int event) { return 1; case FL_PUSH: if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this); + /* fallthrough */ case FL_DRAG: if (Fl::event_inside(this)) { newval = !oldval; @@ -107,6 +108,7 @@ int ComplexButton::handle(int event) { value(0); return 1; } + /* fallthrough */ default: return 0; } diff --git a/dw/fltkimgbuf.cc b/dw/fltkimgbuf.cc index df387dfb4..4eae450bb 100644 --- a/dw/fltkimgbuf.cc +++ b/dw/fltkimgbuf.cc @@ -324,7 +324,8 @@ inline void FltkImgbuf::scaleBuffer (const core::byte *src, int srcWidth, gammaMap2 = findGammaCorrectionTable (1 / gamma); } - for(int x = 0; x < destWidth; x++) + int *v = new int[bpp]; + for(int x = 0; x < destWidth; x++) { for(int y = 0; y < destHeight; y++) { int xo1 = x * srcWidth / destWidth; int xo2 = lout::misc::max ((x + 1) * srcWidth / destWidth, xo1 + 1); @@ -332,7 +333,6 @@ inline void FltkImgbuf::scaleBuffer (const core::byte *src, int srcWidth, int yo2 = lout::misc::max ((y + 1) * srcHeight / destHeight, yo1 + 1); int n = (xo2 - xo1) * (yo2 - yo1); - int v[bpp]; for(int i = 0; i < bpp; i++) v[i] = 0; @@ -349,6 +349,8 @@ inline void FltkImgbuf::scaleBuffer (const core::byte *src, int srcWidth, pd[i] = scaleMode == BEAUTIFUL_GAMMA ? gammaMap1[v[i] / n] : v[i] / n; } + } + delete[] v; } void FltkImgbuf::copyRow (int row, const core::byte *data) diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index 948c14449..0b7ee2e93 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -497,7 +497,7 @@ void FltkPlatform::detachView (core::View *view) { if (this->view != view) MSG_ERR("FltkPlatform::detachView: this->view: %p view: %p\n", - this->view, view); + (void *) this->view, (void *) view); for (container::typed::Iterator it = resources->iterator (); it.hasNext (); ) { diff --git a/dw/fltkui.cc b/dw/fltkui.cc index 712b914fa..e454f85bb 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -460,7 +460,7 @@ void FltkResource::detachView (FltkView *view) { if (this->view != view) MSG_ERR("FltkResource::detachView: this->view: %p view: %p\n", - this->view, view); + (void *) this->view, (void *) view); this->view = NULL; } diff --git a/dw/layout.cc b/dw/layout.cc index a6b77aaf6..5b3000c0e 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -504,8 +504,10 @@ void Layout::attachView (View *view) void Layout::detachView (View *view) { - if (this->view != view) - MSG_ERR("detachView: this->view: %p view %p\n", this->view, view); + if (this->view != view) { + MSG_ERR("detachView: this->view: %p view %p\n", + (void *) this->view, (void *) view); + } view->setLayout (NULL); platform->detachView (view); @@ -865,7 +867,7 @@ void Layout::resizeIdle () enterResizeIdle (); - static int calls = 0; + //static int calls = 0; // There are two commits, 2863:b749629fbfc9 and 4645:ab70f9ce4353, the second // reverting the former. Interrestingly, the second fixes a bug. However, it diff --git a/dw/style.cc b/dw/style.cc index 4c4351a8a..f362710e2 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -773,6 +773,7 @@ static void drawBorderTop(View *view, Style *style, break; case BORDER_DOTTED: dotted = true; + /* fallthrough */ case BORDER_DASHED: w = style->borderWidth.top; view->drawTypedLine(style->borderColor.top, shading, @@ -782,6 +783,7 @@ static void drawBorderTop(View *view, Style *style, case BORDER_SOLID: case BORDER_INSET: inset = true; + /* fallthrough */ case BORDER_OUTSET: if (style->borderStyle.top != BORDER_SOLID) shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT; @@ -801,6 +803,7 @@ static void drawBorderTop(View *view, Style *style, break; case BORDER_RIDGE: ridge = true; + /* fallthrough */ case BORDER_GROOVE: d = style->borderWidth.top & 1; points[0].x = x1; @@ -870,6 +873,7 @@ static void drawBorderBottom(View *view, Style *style, break; case BORDER_DOTTED: dotted = true; + /* fallthrough */ case BORDER_DASHED: w = style->borderWidth.bottom; view->drawTypedLine(style->borderColor.bottom, shading, @@ -879,6 +883,7 @@ static void drawBorderBottom(View *view, Style *style, case BORDER_SOLID: case BORDER_INSET: inset = true; + /* fallthrough */ case BORDER_OUTSET: if (style->borderStyle.bottom != BORDER_SOLID) shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK; @@ -898,6 +903,7 @@ static void drawBorderBottom(View *view, Style *style, break; case BORDER_RIDGE: ridge = true; + /* fallthrough */ case BORDER_GROOVE: w = style->borderWidth.bottom; d = w & 1; @@ -969,6 +975,7 @@ static void drawBorderLeft(View *view, Style *style, break; case BORDER_DOTTED: dotted = true; + /* fallthrough */ case BORDER_DASHED: w = style->borderWidth.left; view->drawTypedLine(style->borderColor.left, shading, @@ -978,6 +985,7 @@ static void drawBorderLeft(View *view, Style *style, case BORDER_SOLID: case BORDER_INSET: inset = true; + /* fallthrough */ case BORDER_OUTSET: if (style->borderStyle.left != BORDER_SOLID) shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT; @@ -996,6 +1004,7 @@ static void drawBorderLeft(View *view, Style *style, break; case BORDER_RIDGE: ridge = true; + /* fallthrough */ case BORDER_GROOVE: w = style->borderWidth.left; d = w & 1; @@ -1066,6 +1075,7 @@ static void drawBorderRight(View *view, Style *style, break; case BORDER_DOTTED: dotted = true; + /* fallthrough */ case BORDER_DASHED: w = style->borderWidth.right; view->drawTypedLine(style->borderColor.right, shading, @@ -1075,6 +1085,7 @@ static void drawBorderRight(View *view, Style *style, case BORDER_SOLID: case BORDER_INSET: inset = true; + /* fallthrough */ case BORDER_OUTSET: if (style->borderStyle.right != BORDER_SOLID) shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK; @@ -1093,6 +1104,7 @@ static void drawBorderRight(View *view, Style *style, break; case BORDER_RIDGE: ridge = true; + /* fallthrough */ case BORDER_GROOVE: w = style->borderWidth.right; d = w & 1; @@ -1419,6 +1431,7 @@ void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType) case LIST_STYLE_TYPE_LOWER_ALPHA: case LIST_STYLE_TYPE_LOWER_LATIN: start_ch = 'a'; + /* fallthrough */ case LIST_STYLE_TYPE_UPPER_ALPHA: case LIST_STYLE_TYPE_UPPER_LATIN: i0 = num - 1; @@ -1433,6 +1446,7 @@ void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType) break; case LIST_STYLE_TYPE_LOWER_ROMAN: low = true; + /* fallthrough */ case LIST_STYLE_TYPE_UPPER_ROMAN: i0 = num; i1 = i0/10; i2 = i1/10; i3 = i2/10; diff --git a/dw/table.cc b/dw/table.cc index b16eedfc4..582c81843 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -714,6 +714,7 @@ void Table::setColExtreme (int col, ExtrMod mod, void *data, int value) switch (mod) { case DATA: ((misc::SimpleVector*)data)->set (col, value); + /* fallthrough */ default: setExtreme (colExtremes->getRef(col), mod, value); diff --git a/dw/textblock.cc b/dw/textblock.cc index 0cef739b8..870ff9e6c 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -1309,7 +1309,7 @@ void Textblock::drawWord (Line *line, int wordIndex1, int wordIndex2, totalWidth += w->size.width; } - char text[l + (drawHyphen ? strlen (hyphenDrawChar) : 0) + 1]; + char *text = new char[l + (drawHyphen ? strlen (hyphenDrawChar) : 0) + 1]; int p = 0; for (int i = wordIndex1; i <= wordIndex2; i++) { const char * t = words->getRef(i)->content.text; @@ -1325,6 +1325,8 @@ void Textblock::drawWord (Line *line, int wordIndex1, int wordIndex2, drawWord0 (wordIndex1, wordIndex2, text, totalWidth, drawHyphen, style, view, area, xWidget, yWidgetBase); + + delete[] text; } } @@ -2066,10 +2068,13 @@ void Textblock::addText (const char *text, size_t len, // Store hyphen positions. int n = 0, totalLenCharRemoved = 0; - int partPenaltyIndex[numParts - 1]; - int partStart[numParts], partEnd[numParts]; - bool charRemoved[numParts - 1], canBeHyphenated[numParts + 1]; - bool permDivChar[numParts - 1], unbreakableForMinWidth[numParts - 1]; + int *partPenaltyIndex = new int[numParts - 1]; + int *partStart = new int[numParts]; + int *partEnd = new int[numParts]; + bool *charRemoved = new bool[numParts - 1]; + bool *canBeHyphenated = new bool[numParts + 1]; + bool *permDivChar = new bool[numParts - 1]; + bool *unbreakableForMinWidth = new bool[numParts - 1]; canBeHyphenated[0] = canBeHyphenated[numParts] = true; partStart[0] = 0; partEnd[numParts - 1] = len; @@ -2134,8 +2139,9 @@ void Textblock::addText (const char *text, size_t len, // Get text without removed characters, e. g. hyphens. const char *textWithoutHyphens; - char textWithoutHyphensBuf[len - totalLenCharRemoved]; - int *breakPosWithoutHyphens, breakPosWithoutHyphensBuf[numParts - 1]; + char *textWithoutHyphensBuf = new char[len - totalLenCharRemoved]; + int *breakPosWithoutHyphens; + int *breakPosWithoutHyphensBuf = new int[numParts - 1]; if (totalLenCharRemoved == 0) { // No removed characters: take original arrays. @@ -2164,7 +2170,7 @@ void Textblock::addText (const char *text, size_t len, PUTCHAR(textWithoutHyphens[i]); PRINTF("'\n"); - core::Requisition wordSize[numParts]; + core::Requisition *wordSize = new core::Requisition[numParts]; calcTextSizes (textWithoutHyphens, len - totalLenCharRemoved, style, numParts - 1, breakPosWithoutHyphens, wordSize); @@ -2228,6 +2234,17 @@ void Textblock::addText (const char *text, size_t len, correctLastWordExtremes (); } } + + delete[] partPenaltyIndex; + delete[] partStart; + delete[] partEnd; + delete[] charRemoved; + delete[] canBeHyphenated; + delete[] permDivChar; + delete[] unbreakableForMinWidth; + delete[] textWithoutHyphensBuf; + delete[] breakPosWithoutHyphensBuf; + delete[] wordSize; } DBG_OBJ_LEAVE (); diff --git a/dw/textblock.hh b/dw/textblock.hh index 0e635b996..d02e6b7b4 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -8,7 +8,7 @@ // These were used when improved line breaking and hyphenation were implemented. // Should be, bit by bit, replaced by RTFL (see ../lout/debug.hh). -#define PRINTF(fmt, ...) +#define PRINTF(...) #define PUTCHAR(ch) #ifdef DBG_RTFL diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc index 14631eba0..b0c20eb2c 100644 --- a/dw/textblock_iterator.cc +++ b/dw/textblock_iterator.cc @@ -113,10 +113,11 @@ void Textblock::TextblockIterator::highlight (int start, int end, oldEndIndex != textblock->hlEnd[layer].index || oldEndChar != textblock->hlEnd[layer].nChar) textblock->queueDrawRange (index1, index2); - } else + } else { highlightOOF (start, end, layer); + } - DBG_OBJ_LEAVE_O (getWidget ()); + DBG_OBJ_LEAVE_O (getWidget ()); } void Textblock::TextblockIterator::unhighlight (int direction, diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index c02453f72..713ad5306 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -1421,7 +1421,7 @@ int Textblock::hyphenateWord (int wordIndex, int *addIndex1) if (numBreaks > 0) { Word origWord = *hyphenatedWord; - core::Requisition wordSize[numBreaks + 1]; + core::Requisition *wordSize = new core::Requisition[numBreaks + 1]; calcTextSizes (origWord.content.text, strlen (origWord.content.text), origWord.style, numBreaks, breakPos, wordSize); @@ -1506,8 +1506,10 @@ int Textblock::hyphenateWord (int wordIndex, int *addIndex1) origWord.spaceStyle->unref (); free (breakPos); - } else + delete[] wordSize; + } else { words->getRef(wordIndex)->flags &= ~Word::CAN_BE_HYPHENATED; + } return numBreaks; } diff --git a/src/dialog.cc b/src/dialog.cc index da623f981..70771be95 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -184,7 +184,7 @@ const char *a_Dialog_input(const char *title, const char *msg) if (!pm) { int n_it = dList_length(prefs.search_urls); pm = new Fl_Menu_Item[n_it+1]; - memset(pm, '\0', sizeof(Fl_Menu_Item[n_it+1])); + memset(pm, '\0', sizeof(*pm)); for (int i = 0, j = 0; i < n_it; i++) { char *label, *url, *source; source = (char *)dList_nth_data(prefs.search_urls, i); diff --git a/src/form.cc b/src/form.cc index aeaa35bde..8234c0a34 100644 --- a/src/form.cc +++ b/src/form.cc @@ -1720,9 +1720,8 @@ void DilloHtmlInput::activate(DilloHtmlForm *form, int num_entry_fields, case DILLO_HTML_INPUT_PASSWORD: if (!(prefs.enterpress_forces_submit || num_entry_fields == 1)) { break; - } else { - /* fall through */ } + /* fallthrough */ case DILLO_HTML_INPUT_SUBMIT: case DILLO_HTML_INPUT_BUTTON_SUBMIT: case DILLO_HTML_INPUT_IMAGE: diff --git a/src/gif.c b/src/gif.c index 2346e2aec..a104ca1d9 100644 --- a/src/gif.c +++ b/src/gif.c @@ -975,7 +975,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf, ibuf += mysize; if (gif->state != 1) break; - + /* fallthrough */ case 1: mysize = Gif_get_descriptor(gif, Buf, ibuf, tmp_bufsize); if (!mysize) @@ -983,7 +983,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf, tmp_bufsize -= mysize; ibuf += mysize; gif->state = 2; - + /* fallthrough */ case 2: /* Ok, this loop construction looks weird. It implements the * of * the GIF grammar. All sorts of stuff is allocated to set up for the @@ -996,7 +996,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf, ibuf += mysize; if (gif->state != 3) break; - + /* fallthrough */ case 3: /* get an image byte */ /* The users sees all of this stuff */ @@ -1005,7 +1005,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf, break; ibuf += mysize; tmp_bufsize -= mysize; - + /* fallthrough */ default: /* error - just consume all input */ tmp_bufsize = 0; diff --git a/src/html.cc b/src/html.cc index 4e2b73d18..b667e5a30 100644 --- a/src/html.cc +++ b/src/html.cc @@ -4130,6 +4130,7 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize) html->ReqTagClose = true; /* Don't break! Open tags may also close themselves */ + /* fallthrough */ default: /* Close function */ diff --git a/src/menu.cc b/src/menu.cc index 865b843b1..b045bf664 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -397,7 +397,7 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, if (cssUrls && cssUrls->size () > 0) { stylesheets = new Fl_Menu_Item[cssUrls->size() + 1]; - memset(stylesheets, '\0', sizeof(Fl_Menu_Item[cssUrls->size() + 1])); + memset(stylesheets, '\0', sizeof(*stylesheets)); for (j = 0; j < cssUrls->size(); j++) { DilloUrl *url = cssUrls->get(j); @@ -638,7 +638,7 @@ void a_Menu_history_popup(BrowserWindow *bw, int x, int y, int direction) ; pm = new Fl_Menu_Item[n + 1]; - memset(pm, '\0', sizeof(Fl_Menu_Item[n + 1])); + memset(pm, '\0', sizeof(*pm)); for (i = 0; i < n; i++) { pm[i].label(FL_NORMAL_LABEL, a_History_get_title(history_list[i], 1)); diff --git a/src/uicmd.cc b/src/uicmd.cc index d289df0c8..03d191ad8 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -1268,7 +1268,7 @@ void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url) Dstr *dstr_url; DilloUrl *vs_url; static int post_id = 0; - char tag[8]; + char tag[16]; const char *content_type = a_Nav_get_content_type(url); a_Misc_parse_content_type(content_type, &major, NULL, NULL); @@ -1281,7 +1281,7 @@ void a_UIcmd_view_page_source(BrowserWindow *bw, const DilloUrl *url) if (URL_FLAGS(url) & URL_Post) { /* append a custom string to differentiate POST URLs */ post_id = (post_id < 9999) ? post_id + 1 : 0; - snprintf(tag, 8, "_%.4d", post_id); + snprintf(tag, 16, "_%.4d", post_id); dStr_append(dstr_url, tag); } vs_url = a_Url_new(dstr_url->str, NULL); From b90186e760e7fc20a4d4c34ad8f6494de459d2ba Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 16:40:13 +0200 Subject: [PATCH 03/28] Remove -Waggregate-return warning It is used by nanosvg library Reviewed-by: dogma --- configure.ac | 3 --- 1 file changed, 3 deletions(-) diff --git a/configure.ac b/configure.ac index 6e878945c..30387f571 100644 --- a/configure.ac +++ b/configure.ac @@ -655,9 +655,6 @@ if eval "test x$GCC = xyes"; then if test "`echo $CFLAGS | grep '\-Wno-unused-parameter' 2> /dev/null`" = ""; then CFLAGS="$CFLAGS -Wno-unused-parameter" fi - if test "`echo $CFLAGS | grep '\-Waggregate-return' 2> /dev/null`" = ""; then - CFLAGS="$CFLAGS -Waggregate-return" - fi fi dnl ----------- dnl CXX options From a9950b3aca2a264e0ee1da1e2a29d3be11e6606c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 14:41:14 +0200 Subject: [PATCH 04/28] Report C compiler and flags on configure summary Reviewed-by: dogma --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index 30387f571..9f3d10208 100644 --- a/configure.ac +++ b/configure.ac @@ -706,6 +706,8 @@ AC_OUTPUT _AS_ECHO([]) _AS_ECHO([Configuration summary:]) _AS_ECHO([]) +_AS_ECHO([ CC : ${CC}]) +_AS_ECHO([ CFLAGS : ${CFLAGS}]) _AS_ECHO([ CXX : ${CXX}]) _AS_ECHO([ CXXFLAGS: ${CXXFLAGS}]) _AS_ECHO([]) From 4d51150ca0aae979718ac10030df85421b763cd1 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 16:35:51 +0200 Subject: [PATCH 05/28] Make Dillo C99 standard compliant Reviewed-by: dogma --- configure.ac | 2 ++ dlib/dlib.c | 4 +-- dlib/dlib.h | 4 +-- dpi/cookies.c | 6 ++-- dpi/datauri.c | 3 +- dpi/file.c | 2 +- dpid/dpid.c | 10 +++--- dpid/dpid.h | 6 ++-- dpid/dpid_common.h | 2 ++ dpid/main.c | 1 - dpid/misc_new.c | 3 +- dw/fltkviewport.cc | 7 ++-- dw/ooffloatsmgr.cc | 2 +- dw/table.cc | 3 ++ dw/table.hh | 17 ++++++---- dw/view.hh | 2 +- src/IO/dpi.c | 10 +++--- src/IO/http.c | 6 ++-- src/IO/mime.c | 2 +- src/IO/tls.c | 2 +- src/IO/tls.h | 4 +-- src/IO/tls_mbedtls.h | 4 +-- src/IO/tls_openssl.c | 6 ++-- src/IO/tls_openssl.h | 4 +-- src/auth.c | 16 ++++----- src/bw.c | 4 +-- src/bw.h | 4 +-- src/cache.c | 3 +- src/cookies.c | 4 +-- src/decode.c | 2 +- src/dialog.cc | 2 +- src/dillo.cc | 3 +- src/dns.c | 12 +------ src/history.c | 4 +-- src/hsts.c | 2 +- src/jpeg.c | 11 +++--- src/md5.c | 3 +- src/menu.cc | 4 +-- src/misc.c | 4 +-- src/misc.h | 1 + src/nanosvg.h | 80 ++++++++++++++++++++++---------------------- src/nanosvgrast.h | 4 +-- src/nav.c | 2 +- src/timeout.hh | 2 +- src/uicmd.hh | 2 +- src/url.c | 3 +- 46 files changed, 144 insertions(+), 140 deletions(-) diff --git a/configure.ac b/configure.ac index 9f3d10208..8d342605c 100644 --- a/configure.ac +++ b/configure.ac @@ -655,7 +655,9 @@ if eval "test x$GCC = xyes"; then if test "`echo $CFLAGS | grep '\-Wno-unused-parameter' 2> /dev/null`" = ""; then CFLAGS="$CFLAGS -Wno-unused-parameter" fi + CFLAGS="$CFLAGS -pedantic -std=c99 -D_POSIX_C_SOURCE=200112L" fi + dnl ----------- dnl CXX options dnl ----------- diff --git a/dlib/dlib.c b/dlib/dlib.c index cd8e8a727..f4c8db2db 100644 --- a/dlib/dlib.c +++ b/dlib/dlib.c @@ -883,7 +883,7 @@ void dLib_show_messages(bool_t show) /** * Return the current working directory in a new string */ -char *dGetcwd () +char *dGetcwd (void) { size_t size = 128; @@ -901,7 +901,7 @@ char *dGetcwd () /** * Return the home directory in a static string (don't free) */ -char *dGethomedir () +char *dGethomedir (void) { static char *homedir = NULL; diff --git a/dlib/dlib.h b/dlib/dlib.h index 87335e00d..81301a55e 100644 --- a/dlib/dlib.h +++ b/dlib/dlib.h @@ -173,8 +173,8 @@ void dLib_show_messages(bool_t show); /* *- Misc utility functions ---------------------------------------------------- */ -char *dGetcwd(); -char *dGethomedir(); +char *dGetcwd(void); +char *dGethomedir(void); char *dGetline(FILE *stream); int dClose(int fd); diff --git a/dpi/cookies.c b/dpi/cookies.c index 420bd69de..f629768e2 100644 --- a/dpi/cookies.c +++ b/dpi/cookies.c @@ -3,7 +3,7 @@ * Cookies server. * * Copyright 2001 Lars Clausen - * Jörgen Viksell + * Jörgen Viksell * Copyright 2002-2007 Jorge Arellano Cid * * This program is free software; you can redistribute it and/or modify @@ -332,7 +332,7 @@ static void Cookies_load_cookies(FILE *stream) * Initialize the cookies module * (The 'disabled' variable is writeable only within Cookies_init) */ -static void Cookies_init() +static void Cookies_init(void) { char *filename; #ifndef HAVE_LOCKF @@ -387,7 +387,7 @@ static void Cookies_init() /* * Flush cookies to disk and free all the memory allocated. */ -static void Cookies_save_and_free() +static void Cookies_save_and_free(void) { int i, fd, saved = 0; DomainNode *node; diff --git a/dpi/datauri.c b/dpi/datauri.c index 0e3560ec8..f968baa2c 100644 --- a/dpi/datauri.c +++ b/dpi/datauri.c @@ -20,6 +20,7 @@ #include "../dpip/dpip.h" #include "dpiutil.h" +#include "../src/misc.h" /* * Debugging macros @@ -44,7 +45,7 @@ static void b64strip_illegal_chars(unsigned char* str) MSG("len=%d{%s}\n", strlen((char*)str), str); for (p = s; (*p = *s); ++s) { - if (isascii(*p) && (isalnum(*p) || strchr("+/=", *p))) + if (d_isascii(*p) && (isalnum(*p) || strchr("+/=", *p))) ++p; } diff --git a/dpi/file.c b/dpi/file.c index df0b49335..ecee90ea6 100644 --- a/dpi/file.c +++ b/dpi/file.c @@ -1000,7 +1000,7 @@ static void File_serve_client(void *data, int f_write) /* * Serve the client queue. */ -static void File_serve_clients() +static void File_serve_clients(void) { int i, f_read, f_write; ClientInfo *client; diff --git a/dpid/dpid.c b/dpid/dpid.c index 06ae86b7a..93df2e6ac 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -47,7 +47,7 @@ char *SharedKey = NULL; * This avoids that dillo instances connect to a stale port after dpid * has exited (e.g. after a reboot). */ -void cleanup() +void cleanup(void) { char *fname; fname = dStrconcat(dGethomedir(), "/", dotDILLO_DPID_COMM_KEYS, NULL); @@ -112,7 +112,7 @@ static void terminator(int sig) /*! Establish handler for termination signals * and register cleanup with atexit */ -void est_dpi_terminator() +void est_dpi_terminator(void) { struct sigaction act; sigset_t block; @@ -526,7 +526,7 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list) * Return a socket file descriptor * (useful to set socket options in a uniform way) */ -static int make_socket_fd() +static int make_socket_fd(void) { int ret, one = 1; @@ -618,7 +618,7 @@ int save_comm_keys(int srs_port) * \li Number of sockets (1 == success) * \li -1 on failure */ -int init_ids_srs_socket() +int init_ids_srs_socket(void) { int srs_port, ret = -1; @@ -806,7 +806,7 @@ void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis) * \Return * Number of available dpis */ -int register_all_cmd() +int register_all_cmd(void) { stop_active_dpis(dpi_attr_list, numdpis); free_plugin_list(&dpi_attr_list, numdpis); diff --git a/dpid/dpid.h b/dpid/dpid.h index 7186d4ffe..b1dc6aabe 100644 --- a/dpid/dpid.h +++ b/dpid/dpid.h @@ -68,7 +68,7 @@ extern volatile sig_atomic_t caught_sigchld; void rm_dpi_sockets(struct dp *dpi_attr_list, int numdpis); -void cleanup(); +void cleanup(void); void free_dpi_attr(struct dp *dpi_attr); @@ -86,7 +86,7 @@ int register_all(struct dp **attlist); int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list); -int init_ids_srs_socket(); +int init_ids_srs_socket(void); int init_dpi_socket(struct dp *dpi_attr); @@ -104,7 +104,7 @@ void stop_active_dpis(struct dp *dpi_attr_list, int numdpis); void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis); -int register_all_cmd(); +int register_all_cmd(void); char *get_message(int sock, char *dpi_tag); diff --git a/dpid/dpid_common.h b/dpid/dpid_common.h index 11bd01489..ca67d67f5 100644 --- a/dpid/dpid_common.h +++ b/dpid/dpid_common.h @@ -10,6 +10,8 @@ */ #include +#include /* size_t */ +#include /* ssize_t */ #include "../dlib/dlib.h" diff --git a/dpid/main.c b/dpid/main.c index 2c3c3271d..b73eb4af6 100644 --- a/dpid/main.c +++ b/dpid/main.c @@ -48,7 +48,6 @@ struct dp *dpi_attr_list; Dlist *services_list; int numsocks; int srs_fd; -; // end of fix diff --git a/dpid/misc_new.c b/dpid/misc_new.c index 94b4d3201..b1355718a 100644 --- a/dpid/misc_new.c +++ b/dpid/misc_new.c @@ -59,7 +59,7 @@ char *a_Misc_readtag(int sock) { char *tag, c; size_t i; - size_t taglen = 0, tagmem = 10; + size_t tagmem = 10; ssize_t rdln = 1; tag = NULL; @@ -71,7 +71,6 @@ char *a_Misc_readtag(int sock) tag = (char *) dRealloc(tag, tagmem + 1); } tag[i] = c; - taglen += rdln; if (c == '>') { tag[i + 1] = '\0'; break; diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc index 91d4ee576..6d2c5ecd5 100644 --- a/dw/fltkviewport.cc +++ b/dw/fltkviewport.cc @@ -121,13 +121,15 @@ void FltkViewport::adjustScrollbarsAndGadgetsAllocation () vscrollbar->resize(x () + w () - SCROLLBAR_THICKNESS, y (), SCROLLBAR_THICKNESS, h () - vdiff); - int X = x () + w () - SCROLLBAR_THICKNESS; - int Y = y () + h () - SCROLLBAR_THICKNESS; + //int X = x () + w () - SCROLLBAR_THICKNESS; + //int Y = y () + h () - SCROLLBAR_THICKNESS; for (Iterator > it = gadgets->iterator (); it.hasNext (); ) { Fl_Widget *widget = it.getNext()->getTypedValue (); widget->resize(x (), y (), SCROLLBAR_THICKNESS, SCROLLBAR_THICKNESS); + /* FIXME: This has no effect */ +#if 0 switch (gadgetOrientation [visibility]) { case GADGET_VERTICAL: Y -= SCROLLBAR_THICKNESS; @@ -137,6 +139,7 @@ void FltkViewport::adjustScrollbarsAndGadgetsAllocation () X -= SCROLLBAR_THICKNESS; break; } +#endif } } diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index aed1f9360..54ea57443 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -548,7 +548,7 @@ int OOFFloatsMgr::addWidgetOOF (Widget *widget, OOFAwareWidget *generatingBlock, DBG_OBJ_ENTER ("construct.oofm", 0, "addWidgetOOF", "%p, %p, %d", widget, generatingBlock, externalIndex); - int subRef; + int subRef = 0; TBInfo *tbInfo = getOOFAwareWidget (generatingBlock); Float *vloat = new Float (this, widget, generatingBlock, externalIndex); diff --git a/dw/table.cc b/dw/table.cc index 582c81843..18bf81cdb 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -1196,10 +1196,13 @@ void Table::actuallyCalcCellSizes (bool calcHeights) for (int col = 0; col < numCols; col++) { int n = row * numCols + col; if (childDefined (n)) { + /* FIXME: Variable width is not used */ +#if 0 int width = (children->get(n)->cell.colspanEff - 1) * getStyle()->hBorderSpacing; for (int i = 0; i < children->get(n)->cell.colspanEff; i++) width += colWidths->get (col + i); +#endif core::Requisition childRequisition; //children->get(n)->cell.widget->setWidth (width); diff --git a/dw/table.hh b/dw/table.hh index 3729da71f..ad1a2ddcf 100644 --- a/dw/table.hh +++ b/dw/table.hh @@ -325,6 +325,14 @@ namespace dw { class Table: public oof::OOFAwareWidget { private: + struct Cell { + core::Widget *widget; + int colspanOrig, colspanEff, rowspan; + }; + struct SpanSpace { + int startCol, startRow; // where the cell starts + }; + struct Child { enum { @@ -332,13 +340,8 @@ private: SPAN_SPACE // part of a spanning cell } type; union { - struct { - core::Widget *widget; - int colspanOrig, colspanEff, rowspan; - } cell; - struct { - int startCol, startRow; // where the cell starts - } spanSpace; + struct Cell cell; + struct SpanSpace spanSpace; }; }; diff --git a/dw/view.hh b/dw/view.hh index 8037dc620..234cc9fb3 100644 --- a/dw/view.hh +++ b/dw/view.hh @@ -48,7 +48,7 @@ public: * Scrolling and Related. Only usesViewport must be * implemented, if it returns false, the other methods * are never called. - * ---------------­-----------­----------------------------- + * --------------------------------------------------------- */ /** diff --git a/src/IO/dpi.c b/src/IO/dpi.c index d7dd7d0b0..c1786de6c 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -419,7 +419,7 @@ static int Dpi_read_comm_keys(int *port) /** * Return a socket file descriptor */ -static int Dpi_make_socket_fd() +static int Dpi_make_socket_fd(void) { int fd, one = 1, ret = -1; @@ -435,7 +435,7 @@ static int Dpi_make_socket_fd() * Make a connection test for a IDS. * Return: 1 OK, -1 Not working. */ -static int Dpi_check_dpid_ids() +static int Dpi_check_dpid_ids(void) { struct sockaddr_in sin; const socklen_t sin_sz = sizeof(sin); @@ -504,12 +504,12 @@ static int Dpi_check_dpid(int num_tries) static int Dpi_blocking_start_dpid(void) { int cst, try = 0, - n_tries = 12; /* 3 seconds */ + n_tries = 3; /* 3 seconds */ /* test the dpid, and wait a bit for it to start if necessary */ while ((cst = Dpi_check_dpid(n_tries)) == 1) { MSG("Dpi_blocking_start_dpid: try %d\n", ++try); - usleep(250000); /* 1/4 sec */ + sleep(1); } return cst; } @@ -757,7 +757,7 @@ void a_Dpi_ccc(int Op, int Branch, int Dir, ChainLink *Info, * Note: currently disabled. It may serve to let the cookies dpi know * when to expire session cookies. */ -void a_Dpi_dillo_exit() +void a_Dpi_dillo_exit(void) { } diff --git a/src/IO/http.c b/src/IO/http.c index 4c4618c58..c7915fc5e 100644 --- a/src/IO/http.c +++ b/src/IO/http.c @@ -234,7 +234,7 @@ void a_Http_connect_done(int fd, bool_t success) dFree(info); } } else { - MSG("**** but no luck with fme %p or sd\n", fme); + MSG("**** but no luck with fme %p or sd\n", (void *) fme); } } @@ -1091,7 +1091,7 @@ static void Http_server_remove(Server_t *srv) dFree(srv); } -static void Http_servers_remove_all() +static void Http_servers_remove_all(void) { Server_t *srv; SocketData_t *sd; @@ -1107,7 +1107,7 @@ static void Http_servers_remove_all() dList_free(servers); } -static void Http_fd_map_remove_all() +static void Http_fd_map_remove_all(void) { FdMapEntry_t *fme; int i, n = dList_length(fd_map); diff --git a/src/IO/mime.c b/src/IO/mime.c index bc70a85f1..1f6a3d47c 100644 --- a/src/IO/mime.c +++ b/src/IO/mime.c @@ -94,7 +94,7 @@ static Viewer_t Mime_major_type_fetch(const char *Key, uint_t Size) /** * Initializes Mime module and, sets the supported Mime types. */ -void a_Mime_init() +void a_Mime_init(void) { #ifdef ENABLE_GIF Mime_add_minor_type("image/gif", a_Dicache_gif_image); diff --git a/src/IO/tls.c b/src/IO/tls.c index 05ae25146..4c0cfe7e5 100644 --- a/src/IO/tls.c +++ b/src/IO/tls.c @@ -28,7 +28,7 @@ /** * Initialize TLS library. */ -void a_Tls_init() +void a_Tls_init(void) { #if ! defined(ENABLE_TLS) MSG("TLS: Disabled at compilation time.\n"); diff --git a/src/IO/tls.h b/src/IO/tls.h index 25da6ea6e..500b24214 100644 --- a/src/IO/tls.h +++ b/src/IO/tls.h @@ -31,13 +31,13 @@ extern "C" { #define TLS_CONNECT_NOT_YET 0 #define TLS_CONNECT_READY 1 -void a_Tls_init(); +void a_Tls_init(void); int a_Tls_certificate_is_clean(const DilloUrl *url); int a_Tls_connect_ready(const DilloUrl *url); void a_Tls_reset_server_state(const DilloUrl *url); void a_Tls_connect(int fd, const DilloUrl *url); void *a_Tls_connection(int fd); -void a_Tls_freeall(); +void a_Tls_freeall(void); void a_Tls_close_by_fd(int fd); int a_Tls_read(void *conn, void *buf, size_t len); int a_Tls_write(void *conn, void *buf, size_t len); diff --git a/src/IO/tls_mbedtls.h b/src/IO/tls_mbedtls.h index 4a6796989..8ce16318a 100644 --- a/src/IO/tls_mbedtls.h +++ b/src/IO/tls_mbedtls.h @@ -21,13 +21,13 @@ extern "C" { #include "../url.h" -void a_Tls_mbedtls_init(); +void a_Tls_mbedtls_init(void); int a_Tls_mbedtls_certificate_is_clean(const DilloUrl *url); int a_Tls_mbedtls_connect_ready(const DilloUrl *url); void a_Tls_mbedtls_reset_server_state(const DilloUrl *url); void a_Tls_mbedtls_connect(int fd, const DilloUrl *url); void *a_Tls_mbedtls_connection(int fd); -void a_Tls_mbedtls_freeall(); +void a_Tls_mbedtls_freeall(void); void a_Tls_mbedtls_close_by_fd(int fd); int a_Tls_mbedtls_read(void *conn, void *buf, size_t len); int a_Tls_mbedtls_write(void *conn, void *buf, size_t len); diff --git a/src/IO/tls_openssl.c b/src/IO/tls_openssl.c index 10a68dbd9..3e68e9283 100644 --- a/src/IO/tls_openssl.c +++ b/src/IO/tls_openssl.c @@ -199,7 +199,7 @@ static void Tls_info_cb(const SSL *ssl, int where, int ret) * abysmal openssl documentation, this was worked out from reading discussion * on the web and then reading openssl source to see what it normally does. */ -static void Tls_load_certificates() +static void Tls_load_certificates(void) { /* curl-7.37.1 says that the following bundle locations are used on "Debian * systems", "Redhat and Mandriva", "old(er) Redhat", "FreeBSD", and @@ -1338,7 +1338,7 @@ void a_Tls_openssl_close_by_fd(int fd) } } -static void Tls_servers_freeall() +static void Tls_servers_freeall(void) { if (servers) { Server_t *s; @@ -1353,7 +1353,7 @@ static void Tls_servers_freeall() } } -static void Tls_fd_map_remove_all() +static void Tls_fd_map_remove_all(void) { if (fd_map) { FdMapEntry_t *fme; diff --git a/src/IO/tls_openssl.h b/src/IO/tls_openssl.h index 5cfd5dfd6..edde93efb 100644 --- a/src/IO/tls_openssl.h +++ b/src/IO/tls_openssl.h @@ -31,13 +31,13 @@ extern "C" { #include "../url.h" -void a_Tls_openssl_init(); +void a_Tls_openssl_init(void); int a_Tls_openssl_certificate_is_clean(const DilloUrl *url); int a_Tls_openssl_connect_ready(const DilloUrl *url); void a_Tls_openssl_reset_server_state(const DilloUrl *url); void a_Tls_openssl_connect(int fd, const DilloUrl *url); void *a_Tls_openssl_connection(int fd); -void a_Tls_openssl_freeall(); +void a_Tls_openssl_freeall(void); void a_Tls_openssl_close_by_fd(int fd); int a_Tls_openssl_read(void *conn, void *buf, size_t len); int a_Tls_openssl_write(void *conn, void *buf, size_t len); diff --git a/src/auth.c b/src/auth.c index 816bc9d36..cb00f4753 100644 --- a/src/auth.c +++ b/src/auth.c @@ -17,7 +17,7 @@ */ -#include /* iscntrl */ +#include /* iscntrl, isascii */ #include "auth.h" #include "msg.h" #include "misc.h" @@ -61,7 +61,7 @@ void a_Auth_init(void) auth_hosts = dList_new(1); } -static AuthParse_t *Auth_parse_new() +static AuthParse_t *Auth_parse_new(void) { AuthParse_t *auth_parse = dNew(AuthParse_t, 1); auth_parse->ok = 0; @@ -105,7 +105,7 @@ static int Auth_path_is_inside(const char *path1, const char *path2, int len) static int Auth_is_token_char(char c) { const char *invalid = "\"()<>@,;:\\[]?=/{} \t"; - return (!isascii(c) || strchr(invalid, c) || iscntrl((uchar_t)c)) ? 0 : 1; + return (!d_isascii(c) || strchr(invalid, c) || iscntrl((uchar_t)c)) ? 0 : 1; } /** @@ -231,7 +231,7 @@ static int Auth_parse_basic_challenge_cb(AuthParse_t *auth_parse, char *token, { if (dStrAsciiCasecmp("realm", token) == 0) { if (!auth_parse->realm) - auth_parse->realm = strdup(value); + auth_parse->realm = dStrdup(value); return 0; /* end parsing */ } else MSG("Auth_parse_basic_challenge_cb: Ignoring unknown parameter: %s = " @@ -245,13 +245,13 @@ static int Auth_parse_digest_challenge_cb(AuthParse_t *auth_parse, char *token, const char *const fn = "Auth_parse_digest_challenge_cb"; if (!dStrAsciiCasecmp("realm", token) && !auth_parse->realm) - auth_parse->realm = strdup(value); + auth_parse->realm = dStrdup(value); else if (!strcmp("domain", token) && !auth_parse->domain) - auth_parse->domain = strdup(value); + auth_parse->domain = dStrdup(value); else if (!strcmp("nonce", token) && !auth_parse->nonce) - auth_parse->nonce = strdup(value); + auth_parse->nonce = dStrdup(value); else if (!strcmp("opaque", token) && !auth_parse->opaque) - auth_parse->opaque = strdup(value); + auth_parse->opaque = dStrdup(value); else if (strcmp("stale", token) == 0) { if (dStrAsciiCasecmp("true", value) == 0) auth_parse->stale = 1; diff --git a/src/bw.c b/src/bw.c index ae3990287..dbc61fa6f 100644 --- a/src/bw.c +++ b/src/bw.c @@ -44,7 +44,7 @@ void a_Bw_init(void) * Create a new browser window and return it. * (the new window is stored in browser_window[]) */ -BrowserWindow *a_Bw_new() +BrowserWindow *a_Bw_new(void) { BrowserWindow *bw; @@ -302,7 +302,7 @@ void a_Bw_cleanup(BrowserWindow *bw) /*--------------------------------------------------------------------------*/ -int a_Bw_num() +int a_Bw_num(void) { return num_bws; } diff --git a/src/bw.h b/src/bw.h index a043e1ea6..d6967ff83 100644 --- a/src/bw.h +++ b/src/bw.h @@ -81,10 +81,10 @@ extern "C" { void a_Bw_init(void); -BrowserWindow *a_Bw_new(); +BrowserWindow *a_Bw_new(void); void a_Bw_free(BrowserWindow *bw); BrowserWindow *a_Bw_get(int i); -int a_Bw_num(); +int a_Bw_num(void); void a_Bw_add_client(BrowserWindow *bw, int Key, int Root); int a_Bw_remove_client(BrowserWindow *bw, int ClientKey); diff --git a/src/cache.c b/src/cache.c index acdeb8b43..8c05c0eb0 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1359,9 +1359,10 @@ static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry) /** * Callback function for Cache_delayed_process_queue. */ -static void Cache_delayed_process_queue_callback() +static void Cache_delayed_process_queue_callback(void *ptr) { CacheEntry_t *entry; + (void) ptr; /* Unused */ while ((entry = (CacheEntry_t *)dList_nth_data(DelayedQueue, 0))) { Cache_ref_data(entry); diff --git a/src/cookies.c b/src/cookies.c index 589c244ff..c2381e049 100644 --- a/src/cookies.c +++ b/src/cookies.c @@ -2,7 +2,7 @@ * File: cookies.c * * Copyright 2001 Lars Clausen - * Jörgen Viksell + * Jörgen Viksell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -132,7 +132,7 @@ void a_Cookies_init(void) /** * Flush cookies to disk and free all the memory allocated. */ -void a_Cookies_freeall() +void a_Cookies_freeall(void) { } diff --git a/src/decode.c b/src/decode.c index 974e1c394..0e95f3863 100644 --- a/src/decode.c +++ b/src/decode.c @@ -304,7 +304,7 @@ DecodeTransfer *a_Decode_transfer_init(const char *format) return dc; } -static Decode *Decode_content_init_common() +static Decode *Decode_content_init_common(void) { z_stream *zs = dNew(z_stream, 1); Decode *dc = dNew(Decode, 1); diff --git a/src/dialog.cc b/src/dialog.cc index 70771be95..349280956 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -184,7 +184,7 @@ const char *a_Dialog_input(const char *title, const char *msg) if (!pm) { int n_it = dList_length(prefs.search_urls); pm = new Fl_Menu_Item[n_it+1]; - memset(pm, '\0', sizeof(*pm)); + memset(pm, '\0', (n_it + 1) * sizeof(Fl_Menu_Item)); for (int i = 0, j = 0; i < n_it; i++) { char *label, *url, *source; source = (char *)dList_nth_data(prefs.search_urls, i); diff --git a/src/dillo.cc b/src/dillo.cc index 889b52560..e9fbfdd72 100644 --- a/src/dillo.cc +++ b/src/dillo.cc @@ -125,6 +125,8 @@ static void raw_sigchld2(int signum) pid_t pid; int status; + (void) signum; /* Unused */ + while (1) { pid = waitpid(-1, &status, WNOHANG); if (pid > 0) { @@ -141,7 +143,6 @@ static void raw_sigchld2(int signum) break; } } - ++signum; /* compiler happiness */ } /** diff --git a/src/dns.c b/src/dns.c index 86b78c9d4..188ee6918 100644 --- a/src/dns.c +++ b/src/dns.c @@ -288,17 +288,7 @@ static void *Dns_server(void *data) if (error != 0) { dns_server[channel].status = error; - if (error == EAI_NONAME) - MSG("DNS error: HOST_NOT_FOUND\n"); - else if (error == EAI_AGAIN) - MSG("DNS error: TRY_AGAIN\n"); -#ifdef EAI_NODATA - /* Some FreeBSD don't have this anymore */ - else if (error == EAI_NODATA) - MSG("DNS error: NO_ADDRESS\n"); -#endif - else if (h_errno == EAI_FAIL) - MSG("DNS error: NO_RECOVERY\n"); + MSG("DNS error: %s\n", gai_strerror(error)); } else { Dns_note_hosts(hosts, res0); dns_server[channel].status = 0; diff --git a/src/history.c b/src/history.c index de77b5c98..49541dfd8 100644 --- a/src/history.c +++ b/src/history.c @@ -33,7 +33,7 @@ static int history_size_max = 16; /** * Debug procedure. */ -void History_show() +void History_show(void) { int i; @@ -149,7 +149,7 @@ void a_History_set_title_by_url(const DilloUrl *url, const char *title) /** * Free all the memory used by this module */ -void a_History_freeall() +void a_History_freeall(void) { int i; diff --git a/src/hsts.c b/src/hsts.c index 435ccfb4f..3ea820708 100644 --- a/src/hsts.c +++ b/src/hsts.c @@ -52,7 +52,7 @@ static void Hsts_free_policy(HstsData_t *p) dFree(p); } -void a_Hsts_freeall() +void a_Hsts_freeall(void) { if (prefs.http_strict_transport_security) { HstsData_t *policy; diff --git a/src/jpeg.c b/src/jpeg.c index 468891fc9..59234d1d9 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -119,13 +119,9 @@ static void Jpeg_close(DilloJpeg *jpeg, CacheClient_t *Client) Jpeg_free(jpeg); } -/* - * The proper signature is: - * static void init_source(j_decompress_ptr cinfo) - * (declaring it with no parameter avoids a compiler warning) - */ -static void init_source() +static void init_source(struct jpeg_decompress_struct *p) { + (void) p; /* unused */ } static boolean fill_input_buffer(j_decompress_ptr cinfo) @@ -181,8 +177,9 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) * static void term_source(j_decompress_ptr cinfo) * (declaring it with no parameter avoids a compiler warning) */ -static void term_source() +static void term_source(struct jpeg_decompress_struct *p) { + (void) p; /* unused */ } void *a_Jpeg_new(DilloImage *Image, DilloUrl *url, int version) diff --git a/src/md5.c b/src/md5.c index 7b7d4e949..7af79d848 100644 --- a/src/md5.c +++ b/src/md5.c @@ -63,6 +63,7 @@ #include "md5.h" #include +#include #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #ifdef ARCH_IS_BIG_ENDIAN @@ -171,7 +172,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) * On little-endian machines, we can process properly aligned * data without copying it. */ - if (!((data - (const md5_byte_t *)0) & 3)) { + if (((uintptr_t) data & 3) == 0) { /* data are properly aligned */ X = (const md5_word_t *)data; } else { diff --git a/src/menu.cc b/src/menu.cc index b045bf664..7cea24a71 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -397,7 +397,7 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, if (cssUrls && cssUrls->size () > 0) { stylesheets = new Fl_Menu_Item[cssUrls->size() + 1]; - memset(stylesheets, '\0', sizeof(*stylesheets)); + memset(stylesheets, '\0', (cssUrls->size() + 1) * sizeof(Fl_Menu_Item)); for (j = 0; j < cssUrls->size(); j++) { DilloUrl *url = cssUrls->get(j); @@ -638,7 +638,7 @@ void a_Menu_history_popup(BrowserWindow *bw, int x, int y, int direction) ; pm = new Fl_Menu_Item[n + 1]; - memset(pm, '\0', sizeof(*pm)); + memset(pm, '\0', (n + 1) * sizeof(Fl_Menu_Item)); for (i = 0; i < n; i++) { pm[i].label(FL_NORMAL_LABEL, a_History_get_title(history_list[i], 1)); diff --git a/src/misc.c b/src/misc.c index d6fbb83bc..9129f8193 100644 --- a/src/misc.c +++ b/src/misc.c @@ -222,13 +222,13 @@ void a_Misc_parse_content_type(const char *type, char **major, char **minor, if (!(str = type)) return; - for (s = str; *s && isascii((uchar_t)*s) && !iscntrl((uchar_t)*s) && + for (s = str; *s && d_isascii((uchar_t)*s) && !iscntrl((uchar_t)*s) && !strchr(tspecials_space, *s); s++) ; if (major) *major = dStrndup(str, s - str); if (*s == '/') { - for (str = ++s; *s && isascii((uchar_t)*s) && !iscntrl((uchar_t)*s) && + for (str = ++s; *s && d_isascii((uchar_t)*s) && !iscntrl((uchar_t)*s) && !strchr(tspecials_space, *s); s++) ; if (minor) *minor = dStrndup(str, s - str); diff --git a/src/misc.h b/src/misc.h index 75f0f78a4..5e52b5b39 100644 --- a/src/misc.h +++ b/src/misc.h @@ -8,6 +8,7 @@ extern "C" { #endif /* __cplusplus */ +#define d_isascii(c) (((c) & ~0x7f) == 0) char *a_Misc_escape_chars(const char *str, const char *esc_set); int a_Misc_expand_tabs(char **start, char *end, char *buf, int buflen); diff --git a/src/nanosvg.h b/src/nanosvg.h index 98b06bead..77617f65a 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -125,7 +125,7 @@ typedef struct NSVGpaint { union { unsigned int color; NSVGgradient* gradient; - }; + } v; } NSVGpaint; typedef struct NSVGpath @@ -405,7 +405,7 @@ typedef struct NSVGgradientData union { NSVGlinearData linear; NSVGradialData radial; - }; + } grad; char spread; char units; float xform[6]; @@ -673,7 +673,7 @@ static void nsvg__deletePaths(NSVGpath* path) static void nsvg__deletePaint(NSVGpaint* paint) { if (paint->type == NSVG_PAINT_LINEAR_GRADIENT || paint->type == NSVG_PAINT_RADIAL_GRADIENT) - free(paint->gradient); + free(paint->v.gradient); } static void nsvg__deleteGradientData(NSVGgradientData* grad) @@ -875,10 +875,10 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f if (data->type == NSVG_PAINT_LINEAR_GRADIENT) { float x1, y1, x2, y2, dx, dy; - x1 = nsvg__convertToPixels(p, data->linear.x1, ox, sw); - y1 = nsvg__convertToPixels(p, data->linear.y1, oy, sh); - x2 = nsvg__convertToPixels(p, data->linear.x2, ox, sw); - y2 = nsvg__convertToPixels(p, data->linear.y2, oy, sh); + x1 = nsvg__convertToPixels(p, data->grad.linear.x1, ox, sw); + y1 = nsvg__convertToPixels(p, data->grad.linear.y1, oy, sh); + x2 = nsvg__convertToPixels(p, data->grad.linear.x2, ox, sw); + y2 = nsvg__convertToPixels(p, data->grad.linear.y2, oy, sh); // Calculate transform aligned to the line dx = x2 - x1; dy = y2 - y1; @@ -887,11 +887,11 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f grad->xform[4] = x1; grad->xform[5] = y1; } else { float cx, cy, fx, fy, r; - cx = nsvg__convertToPixels(p, data->radial.cx, ox, sw); - cy = nsvg__convertToPixels(p, data->radial.cy, oy, sh); - fx = nsvg__convertToPixels(p, data->radial.fx, ox, sw); - fy = nsvg__convertToPixels(p, data->radial.fy, oy, sh); - r = nsvg__convertToPixels(p, data->radial.r, 0, sl); + cx = nsvg__convertToPixels(p, data->grad.radial.cx, ox, sw); + cy = nsvg__convertToPixels(p, data->grad.radial.cy, oy, sh); + fx = nsvg__convertToPixels(p, data->grad.radial.fx, ox, sw); + fy = nsvg__convertToPixels(p, data->grad.radial.fy, oy, sh); + r = nsvg__convertToPixels(p, data->grad.radial.r, 0, sl); // Calculate transform aligned to the circle grad->xform[0] = r; grad->xform[1] = 0; grad->xform[2] = 0; grad->xform[3] = r; @@ -1001,8 +1001,8 @@ static void nsvg__addShape(NSVGparser* p) shape->fill.type = NSVG_PAINT_NONE; } else if (attr->hasFill == 1) { shape->fill.type = NSVG_PAINT_COLOR; - shape->fill.color = attr->fillColor; - shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24; + shape->fill.v.color = attr->fillColor; + shape->fill.v.color |= (unsigned int)(attr->fillOpacity*255) << 24; } else if (attr->hasFill == 2) { shape->fill.type = NSVG_PAINT_UNDEF; } @@ -1012,8 +1012,8 @@ static void nsvg__addShape(NSVGparser* p) shape->stroke.type = NSVG_PAINT_NONE; } else if (attr->hasStroke == 1) { shape->stroke.type = NSVG_PAINT_COLOR; - shape->stroke.color = attr->strokeColor; - shape->stroke.color |= (unsigned int)(attr->strokeOpacity*255) << 24; + shape->stroke.v.color = attr->strokeColor; + shape->stroke.v.color |= (unsigned int)(attr->strokeOpacity*255) << 24; } else if (attr->hasStroke == 2) { shape->stroke.type = NSVG_PAINT_UNDEF; } @@ -2717,14 +2717,14 @@ static void nsvg__parseGradient(NSVGparser* p, const char** attr, signed char ty grad->units = NSVG_OBJECT_SPACE; grad->type = type; if (grad->type == NSVG_PAINT_LINEAR_GRADIENT) { - grad->linear.x1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); - grad->linear.y1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); - grad->linear.x2 = nsvg__coord(100.0f, NSVG_UNITS_PERCENT); - grad->linear.y2 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); + grad->grad.linear.x1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); + grad->grad.linear.y1 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); + grad->grad.linear.x2 = nsvg__coord(100.0f, NSVG_UNITS_PERCENT); + grad->grad.linear.y2 = nsvg__coord(0.0f, NSVG_UNITS_PERCENT); } else if (grad->type == NSVG_PAINT_RADIAL_GRADIENT) { - grad->radial.cx = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); - grad->radial.cy = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); - grad->radial.r = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); + grad->grad.radial.cx = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); + grad->grad.radial.cy = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); + grad->grad.radial.r = nsvg__coord(50.0f, NSVG_UNITS_PERCENT); } nsvg__xformIdentity(grad->xform); @@ -2742,23 +2742,23 @@ static void nsvg__parseGradient(NSVGparser* p, const char** attr, signed char ty } else if (strcmp(attr[i], "gradientTransform") == 0) { nsvg__parseTransform(grad->xform, attr[i + 1]); } else if (strcmp(attr[i], "cx") == 0) { - grad->radial.cx = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.radial.cx = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "cy") == 0) { - grad->radial.cy = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.radial.cy = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "r") == 0) { - grad->radial.r = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.radial.r = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "fx") == 0) { - grad->radial.fx = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.radial.fx = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "fy") == 0) { - grad->radial.fy = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.radial.fy = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "x1") == 0) { - grad->linear.x1 = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.linear.x1 = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "y1") == 0) { - grad->linear.y1 = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.linear.y1 = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "x2") == 0) { - grad->linear.x2 = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.linear.x2 = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "y2") == 0) { - grad->linear.y2 = nsvg__parseCoordinateRaw(attr[i + 1]); + grad->grad.linear.y2 = nsvg__parseCoordinateRaw(attr[i + 1]); } else if (strcmp(attr[i], "spreadMethod") == 0) { if (strcmp(attr[i+1], "pad") == 0) grad->spread = NSVG_SPREAD_PAD; @@ -3050,14 +3050,14 @@ static void nsvg__scaleToViewbox(NSVGparser* p, const char* units) } if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT || shape->fill.type == NSVG_PAINT_RADIAL_GRADIENT) { - nsvg__scaleGradient(shape->fill.gradient, tx,ty, sx,sy); - memcpy(t, shape->fill.gradient->xform, sizeof(float)*6); - nsvg__xformInverse(shape->fill.gradient->xform, t); + nsvg__scaleGradient(shape->fill.v.gradient, tx,ty, sx,sy); + memcpy(t, shape->fill.v.gradient->xform, sizeof(float)*6); + nsvg__xformInverse(shape->fill.v.gradient->xform, t); } if (shape->stroke.type == NSVG_PAINT_LINEAR_GRADIENT || shape->stroke.type == NSVG_PAINT_RADIAL_GRADIENT) { - nsvg__scaleGradient(shape->stroke.gradient, tx,ty, sx,sy); - memcpy(t, shape->stroke.gradient->xform, sizeof(float)*6); - nsvg__xformInverse(shape->stroke.gradient->xform, t); + nsvg__scaleGradient(shape->stroke.v.gradient, tx,ty, sx,sy); + memcpy(t, shape->stroke.v.gradient->xform, sizeof(float)*6); + nsvg__xformInverse(shape->stroke.v.gradient->xform, t); } shape->strokeWidth *= avgs; @@ -3080,7 +3080,7 @@ static void nsvg__createGradients(NSVGparser* p) float inv[6], localBounds[4]; nsvg__xformInverse(inv, shape->xform); nsvg__getLocalBounds(localBounds, shape, inv); - shape->fill.gradient = nsvg__createGradient(p, shape->fillGradient, localBounds, shape->xform, &shape->fill.type); + shape->fill.v.gradient = nsvg__createGradient(p, shape->fillGradient, localBounds, shape->xform, &shape->fill.type); } if (shape->fill.type == NSVG_PAINT_UNDEF) { shape->fill.type = NSVG_PAINT_NONE; @@ -3091,7 +3091,7 @@ static void nsvg__createGradients(NSVGparser* p) float inv[6], localBounds[4]; nsvg__xformInverse(inv, shape->xform); nsvg__getLocalBounds(localBounds, shape, inv); - shape->stroke.gradient = nsvg__createGradient(p, shape->strokeGradient, localBounds, shape->xform, &shape->stroke.type); + shape->stroke.v.gradient = nsvg__createGradient(p, shape->strokeGradient, localBounds, shape->xform, &shape->stroke.type); } if (shape->stroke.type == NSVG_PAINT_UNDEF) { shape->stroke.type = NSVG_PAINT_NONE; diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h index 89a2e2438..35175ee9b 100644 --- a/src/nanosvgrast.h +++ b/src/nanosvgrast.h @@ -1288,11 +1288,11 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opac cache->type = paint->type; if (paint->type == NSVG_PAINT_COLOR) { - cache->colors[0] = nsvg__applyOpacity(paint->color, opacity); + cache->colors[0] = nsvg__applyOpacity(paint->v.color, opacity); return; } - grad = paint->gradient; + grad = paint->v.gradient; cache->spread = grad->spread; memcpy(cache->xform, grad->xform, sizeof(float)*6); diff --git a/src/nav.c b/src/nav.c index cddfe21b6..7b620b669 100644 --- a/src/nav.c +++ b/src/nav.c @@ -555,7 +555,7 @@ static void Nav_save_cb(int Op, CacheClient_t *Client) a_UIcmd_set_msg(Web->bw, "File saved (%d Bytes)", st.st_size); } else { if ((Bytes = Client->BufSize - Web->SavedBytes) > 0) { - Bytes = fwrite(Client->Buf + Web->SavedBytes, 1, Bytes, Web->stream); + Bytes = fwrite((char *) Client->Buf + Web->SavedBytes, 1, Bytes, Web->stream); Web->SavedBytes += Bytes; } } diff --git a/src/timeout.hh b/src/timeout.hh index 5b7f47592..14f24e2a6 100644 --- a/src/timeout.hh +++ b/src/timeout.hh @@ -9,7 +9,7 @@ typedef void (*TimeoutCb_t)(void *data); void a_Timeout_add(float t, TimeoutCb_t cb, void *cbdata); void a_Timeout_repeat(float t, TimeoutCb_t cb, void *cbdata); -void a_Timeout_remove(); +void a_Timeout_remove(void); #ifdef __cplusplus diff --git a/src/uicmd.hh b/src/uicmd.hh index ec630d657..0a5c8fb5d 100644 --- a/src/uicmd.hh +++ b/src/uicmd.hh @@ -44,7 +44,7 @@ void a_UIcmd_stop(void *vbw); void a_UIcmd_tools(void *vbw, int x, int y); void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url); void a_UIcmd_open_file(void *vbw); -const char *a_UIcmd_select_file(); +const char *a_UIcmd_select_file(void); void a_UIcmd_search_dialog(void *vbw); const char *a_UIcmd_get_passwd(const char *user); void a_UIcmd_book(void *vbw); diff --git a/src/url.c b/src/url.c index 0c34d1d92..545690134 100644 --- a/src/url.c +++ b/src/url.c @@ -48,6 +48,7 @@ #include "url.h" #include "hsts.h" +#include "misc.h" #include "msg.h" static const char *HEX = "0123456789ABCDEF"; @@ -627,7 +628,7 @@ char *a_Url_encode_hex_str(const char *str) newstr = dNew(char, 6*strlen(str)+1); for (c = newstr; *str; str++) - if ((dIsalnum(*str) && isascii(*str)) || strchr(verbatim, *str)) + if ((dIsalnum(*str) && d_isascii(*str)) || strchr(verbatim, *str)) *c++ = *str; else if (*str == ' ') *c++ = '+'; From b233f929d9a6afd8effd175dbc8d27db079ecb5c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 28 Jul 2024 16:38:15 +0200 Subject: [PATCH 06/28] Fail on warnings in CI Reviewed-by: dogma --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17bbd9259..d78cb9fbd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -127,7 +127,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --disable-mbedtls CFLAGS="-std=gnu99" CXXFLAGS="-std=c++98" + run: ./configure --disable-mbedtls CFLAGS="-Werror" CXXFLAGS="-Werror" - name: make run: make - name: make check From a00e68d5486a9382988a1ca25c52a305c8a020bf Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 29 Jul 2024 19:52:43 +0200 Subject: [PATCH 07/28] Build tests with -pedantic Reviewed-by: dogma --- test/unit/cookies.c | 4 ++-- test/unit/unicode_test.cc | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unit/cookies.c b/test/unit/cookies.c index 923f52274..ce122ffc7 100644 --- a/test/unit/cookies.c +++ b/test/unit/cookies.c @@ -277,12 +277,12 @@ static int Dpi_check_dpid(int num_tries) static int Dpi_blocking_start_dpid(void) { int cst, try = 0, - n_tries = 12; /* 3 seconds */ + n_tries = 3; /* 3 seconds */ /* test the dpid, and wait a bit for it to start if necessary */ while ((cst = Dpi_check_dpid(n_tries)) == 1) { MSG("Dpi_blocking_start_dpid: try %d\n", ++try); - usleep(250000); /* 1/4 sec */ + sleep(1); /* 1/4 sec */ } return cst; } diff --git a/test/unit/unicode_test.cc b/test/unit/unicode_test.cc index 0824cdd04..ffcc16271 100644 --- a/test/unit/unicode_test.cc +++ b/test/unit/unicode_test.cc @@ -32,7 +32,7 @@ int main (int argc, char *argv[]) // not 0-terminated; copy from 0-terminated int t2len = strlen (t1); - char t2[t2len]; + char *t2 = new char[t2len]; for (int i = 0; i < t2len; i++) t2[i] = t1[i]; @@ -54,5 +54,7 @@ int main (int argc, char *argv[]) printf ("%3d -> U+%04x\n", (int)(s - t2), decodeUtf8(s, t2len - (s - t2))); + delete[] t2; + return 0; } From 59c9094781cbf340f11929d497c1465cf45cf90a Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 29 Jul 2024 20:17:36 +0200 Subject: [PATCH 08/28] Add portable usleep() replacement Reviewed-by: dogma --- dlib/dlib.c | 23 +++++++++++++++++++++++ dlib/dlib.h | 1 + 2 files changed, 24 insertions(+) diff --git a/dlib/dlib.c b/dlib/dlib.c index f4c8db2db..2cbd083e5 100644 --- a/dlib/dlib.c +++ b/dlib/dlib.c @@ -2,6 +2,7 @@ * File: dlib.c * * Copyright (C) 2006-2007 Jorge Arellano Cid + * Copyright (C) 2024 Rodrigo Arias Mallo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,7 @@ #include #include #include +#include #include "dlib.h" @@ -955,3 +957,24 @@ int dClose(int fd) while (st == -1 && errno == EINTR); return st; } + +/** + * Portable usleep() function. + * + * The usleep() function is deprecated in POSIX.1-2001 and removed in + * POSIX.1-2008, see usleep(3). + */ +int dUsleep(unsigned long usec) +{ + struct timespec ts; + int res; + + ts.tv_sec = usec / 1000000UL; + ts.tv_nsec = (usec % 1000000UL) * 1000UL; + + do { + res = nanosleep(&ts, &ts); + } while (res && errno == EINTR); + + return res; +} diff --git a/dlib/dlib.h b/dlib/dlib.h index 81301a55e..351294ff9 100644 --- a/dlib/dlib.h +++ b/dlib/dlib.h @@ -177,6 +177,7 @@ char *dGetcwd(void); char *dGethomedir(void); char *dGetline(FILE *stream); int dClose(int fd); +int dUsleep(unsigned long us); #ifdef __cplusplus } From 49ae3fd3edb957a8a2f7c7541c66b9336f25176e Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 29 Jul 2024 20:18:14 +0200 Subject: [PATCH 09/28] Use portable dUsleep() instead of usleep() Reviewed-by: dogma --- src/IO/dpi.c | 5 +++-- test/unit/cookies.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/IO/dpi.c b/src/IO/dpi.c index c1786de6c..46ddc49e5 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -39,6 +39,7 @@ #include "IO.h" #include "Url.h" #include "../../dpip/dpip.h" +#include "dlib/dlib.h" /* This one is tricky, some sources state it should include the byte * for the terminating NULL, and others say it shouldn't. */ @@ -504,12 +505,12 @@ static int Dpi_check_dpid(int num_tries) static int Dpi_blocking_start_dpid(void) { int cst, try = 0, - n_tries = 3; /* 3 seconds */ + n_tries = 12; /* 3 seconds */ /* test the dpid, and wait a bit for it to start if necessary */ while ((cst = Dpi_check_dpid(n_tries)) == 1) { MSG("Dpi_blocking_start_dpid: try %d\n", ++try); - sleep(1); + dUsleep(250000UL); } return cst; } diff --git a/test/unit/cookies.c b/test/unit/cookies.c index ce122ffc7..caef5d7bf 100644 --- a/test/unit/cookies.c +++ b/test/unit/cookies.c @@ -277,12 +277,12 @@ static int Dpi_check_dpid(int num_tries) static int Dpi_blocking_start_dpid(void) { int cst, try = 0, - n_tries = 3; /* 3 seconds */ + n_tries = 12; /* 3 seconds */ /* test the dpid, and wait a bit for it to start if necessary */ while ((cst = Dpi_check_dpid(n_tries)) == 1) { MSG("Dpi_blocking_start_dpid: try %d\n", ++try); - sleep(1); /* 1/4 sec */ + dUsleep(250000U); /* 1/4 sec */ } return cst; } From 83e88446c99f793f696984904e47070a287fd15d Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 31 Jul 2024 00:25:03 +0200 Subject: [PATCH 10/28] Avoid INADDR_LOOPBACK as it is an extension Instead use inet_addr("127.0.0.1") which is POSIX 2001 and also more clear. Reviewed-by: dogma --- dpid/dpid.c | 6 ++++-- dpid/dpidc.c | 3 ++- src/IO/dpi.c | 8 ++++---- test/unit/cookies.c | 6 +++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dpid/dpid.c b/dpid/dpid.c index 93df2e6ac..9bf28f46d 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include #include #include "dpid_common.h" @@ -564,7 +566,7 @@ int bind_socket_fd(int base_port, int *p_port) memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Try to bind a port on localhost */ for (port = base_port; port <= last_port; ++port) { @@ -754,7 +756,7 @@ void stop_active_dpis(struct dp *dpi_attr_list, int numdpis) memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); for (i = 0; i < numdpis; i++) { /* Skip inactive dpis and filters */ diff --git a/dpid/dpidc.c b/dpid/dpidc.c index ca6101278..f9e579b2b 100644 --- a/dpid/dpidc.c +++ b/dpid/dpidc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -91,7 +92,7 @@ int main(int argc, char *argv[]) error("ERROR opening socket"); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); serv_addr.sin_port = htons(portno); if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 46ddc49e5..2d265b781 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -26,6 +26,7 @@ #include /* for errno */ #include #include /* isxdigit */ +#include #include #include @@ -51,7 +52,6 @@ #define AF_LOCAL AF_UNIX #endif - typedef struct { int InTag; int Send2EOF; @@ -445,7 +445,7 @@ static int Dpi_check_dpid_ids(void) /* socket connection test */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); if (Dpi_read_comm_keys(&dpid_port) != -1) { sin.sin_port = htons(dpid_port); @@ -544,7 +544,7 @@ static int Dpi_get_server_port(const char *server_name) sin_sz = sizeof(sin); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_port = htons(dpid_port); if ((sock_fd = Dpi_make_socket_fd()) == -1 || connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) { @@ -617,7 +617,7 @@ static int Dpi_connect_socket(const char *server_name) /* connect with this server's socket */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_port = htons(dpi_port); if ((sock_fd = Dpi_make_socket_fd()) == -1) { diff --git a/test/unit/cookies.c b/test/unit/cookies.c index caef5d7bf..40a194184 100644 --- a/test/unit/cookies.c +++ b/test/unit/cookies.c @@ -148,7 +148,7 @@ static int Dpi_check_dpid_ids() /* socket connection test */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); if (Dpi_read_comm_keys(&dpid_port) != -1) { sin.sin_port = htons(dpid_port); @@ -317,7 +317,7 @@ static int Dpi_get_server_port(const char *server_name) sin_sz = sizeof(sin); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_port = htons(dpid_port); if ((sock_fd = Dpi_make_socket_fd()) == -1 || connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) { @@ -385,7 +385,7 @@ static int Dpi_connect_socket(const char *server_name) /* connect with this server's socket */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_port = htons(dpi_port); if ((sock_fd = Dpi_make_socket_fd()) == -1) { From f1b04c40ba9faf9b7b8969cf3686c35bb7b79b33 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 6 Aug 2024 14:15:07 +0200 Subject: [PATCH 11/28] Use dStrdup instead of strdup The strdup function is not available in POSIX-2001, so we use our own implementation in dlib: dStrdup. Reviewed-by: dogma --- dw/findtext.cc | 3 ++- dw/fltkplatform.cc | 3 ++- dw/fltkui.cc | 23 ++++++++++++----------- dw/hyphenator.cc | 3 ++- dw/image.cc | 3 ++- dw/layout.cc | 5 +++-- dw/style.cc | 3 ++- dw/textblock.cc | 2 +- lout/misc.cc | 8 ++++---- lout/misc.hh | 3 ++- lout/object.cc | 5 +++-- src/css.cc | 2 +- src/dialog.cc | 3 ++- src/form.cc | 3 ++- src/tipwin.cc | 9 +++++---- test/dw/Makefile.am | 1 + test/dw/dw_anchors_test.cc | 3 ++- test/dw/form.cc | 11 ++++++----- test/unit/Makefile.am | 9 +++++++++ 19 files changed, 63 insertions(+), 39 deletions(-) diff --git a/dw/findtext.cc b/dw/findtext.cc index 94b963eae..0a4d25c53 100644 --- a/dw/findtext.cc +++ b/dw/findtext.cc @@ -20,6 +20,7 @@ #include "core.hh" +#include "dlib/dlib.h" #include "../lout/debug.hh" #include "../lout/msg.h" @@ -87,7 +88,7 @@ FindtextState::Result FindtextState::search (const char *key, bool caseSens, newKey = true; if (this->key) free(this->key); - this->key = strdup (key); + this->key = dStrdup (key); this->caseSens = caseSens; if (nexttab) diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index 0b7ee2e93..f5d686c45 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -19,6 +19,7 @@ #include +#include "dlib/dlib.h" #include "../lout/msg.h" #include "../lout/debug.hh" #include "fltkcore.hh" @@ -145,7 +146,7 @@ void FltkFont::initSystemFonts () int k = Fl::set_fonts ("-*-iso10646-1"); for (int i = 0; i < k; i++) { int t; - char *name = strdup (Fl::get_font_name ((Fl_Font) i, &t)); + char *name = dStrdup (Fl::get_font_name ((Fl_Font) i, &t)); // normalize font family names (strip off "bold", "italic") if (t & FL_ITALIC) diff --git a/dw/fltkui.cc b/dw/fltkui.cc index e454f85bb..c650712a2 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -22,6 +22,7 @@ #include "fltkcore.hh" #include "fltkflatview.hh" #include "fltkcomplexbutton.hh" +#include "dlib/dlib.h" #include "../lout/msg.h" #include "../lout/misc.hh" @@ -112,7 +113,7 @@ void CustInput2::set_placeholder(const char *str) { if (placeholder) free(placeholder); - placeholder = strdup(str); + placeholder = dStrdup(str); if ((Fl::focus() != this) && !*value()) { show_placeholder(); @@ -276,7 +277,7 @@ void CustTextEditor::set_placeholder(const char *str) { if (placeholder) free(placeholder); - placeholder = strdup(str); + placeholder = dStrdup(str); if ((Fl::focus() != this) && buffer()->length() == 0) { show_placeholder(); @@ -315,7 +316,7 @@ char* CustTextEditor::value() */ if (text_copy) free(text_copy); - text_copy = showing_placeholder ? strdup("") : buffer()->text(); + text_copy = showing_placeholder ? dStrdup("") : buffer()->text(); return text_copy; } @@ -625,7 +626,7 @@ FltkLabelButtonResource::FltkLabelButtonResource (FltkPlatform *platform, const char *label): FltkSpecificResource (platform) { - this->label = strdup (label); + this->label = dStrdup (label); init (platform); } @@ -717,7 +718,7 @@ const char *FltkLabelButtonResource::getLabel () void FltkLabelButtonResource::setLabel (const char *label) { free((char *)this->label); - this->label = strdup (label); + this->label = dStrdup (label); widget->label (this->label); queueResize (true); @@ -866,9 +867,9 @@ FltkEntryResource::FltkEntryResource (FltkPlatform *platform, int size, { this->size = size; this->password = password; - this->label = label ? strdup(label) : NULL; + this->label = label ? dStrdup(label) : NULL; this->label_w = 0; - this->placeholder = placeholder ? strdup(placeholder) : NULL; + this->placeholder = placeholder ? dStrdup(placeholder) : NULL; initText = NULL; editable = false; @@ -994,7 +995,7 @@ void FltkEntryResource::setText (const char *text) { if (initText) free((char *)initText); - initText = strdup (text); + initText = dStrdup (text); ((CustInput2*)widget)->value (initText); } @@ -1052,7 +1053,7 @@ FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform, MSG_WARN("numRows = %d is set to 1.\n", numRows); numRows = 1; } - this->placeholder = placeholder ? strdup(placeholder) : NULL; + this->placeholder = placeholder ? dStrdup(placeholder) : NULL; init (platform); } @@ -1492,7 +1493,7 @@ void FltkOptionMenuResource::addItem (const char *str, { Fl_Menu_Item *item = newItem(); - item->text = strdup(str); + item->text = dStrdup(str); if (enabled == false) item->flags = FL_MENU_INACTIVE; @@ -1513,7 +1514,7 @@ void FltkOptionMenuResource::pushGroup (const char *name, bool enabled) { Fl_Menu_Item *item = newItem(); - item->text = strdup(name); + item->text = dStrdup(name); if (enabled == false) item->flags = FL_MENU_INACTIVE; diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc index 739590dc1..1530074f8 100644 --- a/dw/hyphenator.cc +++ b/dw/hyphenator.cc @@ -21,6 +21,7 @@ #include "hyphenator.hh" +#include "dlib/dlib.h" #include "../lout/misc.hh" #include "../lout/unicode.hh" #include @@ -395,7 +396,7 @@ TrieBuilder::~TrieBuilder () void TrieBuilder::insert (const char *key, const char *value) { dataList->increase (); - dataList->getLastRef ()->key = (unsigned char *) strdup(key); + dataList->getLastRef ()->key = (unsigned char *) dStrdup(key); dataList->getLastRef ()->value = dataZone->strdup (value); } diff --git a/dw/image.cc b/dw/image.cc index 821189499..fc914f443 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -20,6 +20,7 @@ #include "image.hh" +#include "dlib/dlib.h" #include "../lout/msg.h" #include "../lout/misc.hh" #include "../lout/debug.hh" @@ -146,7 +147,7 @@ Image::Image(const char *altText) { DBG_OBJ_CREATE ("dw::Image"); registerName ("dw::Image", &CLASS_ID); - this->altText = altText ? strdup (altText) : NULL; + this->altText = altText ? dStrdup (altText) : NULL; altTextWidth = -1; // not yet calculated buffer = NULL; bufWidth = bufHeight = -1; diff --git a/dw/layout.cc b/dw/layout.cc index 5b3000c0e..966536430 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -22,6 +22,7 @@ #include "core.hh" +#include "dlib/dlib.h" #include "../lout/msg.h" #include "../lout/debug.hh" #include "../lout/misc.hh" @@ -735,7 +736,7 @@ void Layout::setAnchor (const char *anchor) if (requestedAnchor) free (requestedAnchor); - requestedAnchor = anchor ? strdup (anchor) : NULL; + requestedAnchor = anchor ? dStrdup (anchor) : NULL; updateAnchor (); } @@ -754,7 +755,7 @@ char *Layout::addAnchor (Widget *widget, const char* name, int y) return NULL; else { Anchor *anchor = new Anchor (); - anchor->name = strdup (name); + anchor->name = dStrdup (name); anchor->widget = widget; anchor->y = y; diff --git a/dw/style.cc b/dw/style.cc index f362710e2..5d0bcbe39 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -23,6 +23,7 @@ #include #include +#include "dlib/dlib.h" #include "core.hh" #include "../lout/msg.h" @@ -426,7 +427,7 @@ Font::~Font () void Font::copyAttrs (FontAttrs *attrs) { - name = strdup (attrs->name); + name = dStrdup (attrs->name); size = attrs->size; weight = attrs->weight; style = attrs->style; diff --git a/dw/textblock.cc b/dw/textblock.cc index 870ff9e6c..df34dd950 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -2553,7 +2553,7 @@ void Textblock::addWidget (core::Widget *widget, core::style::Style *style) } /** - * Add an anchor to the page. "name" is copied, so no strdup is necessary for + * Add an anchor to the page. "name" is copied, so no dStrdup is necessary for * the caller. * * Return true on success, and false, when this anchor had already been diff --git a/lout/misc.cc b/lout/misc.cc index bffc68f7c..c6e057fa3 100644 --- a/lout/misc.cc +++ b/lout/misc.cc @@ -32,10 +32,10 @@ namespace misc { const char *prgName = PRGNAME; -void init (int argc, char *argv[]) -{ - prgName = strdup (argv[0]); -} +//void init (int argc, char *argv[]) +//{ +// prgName = dStrdup (argv[0]); +//} // ------------------ diff --git a/lout/misc.hh b/lout/misc.hh index 80f227f84..1108c1eb0 100644 --- a/lout/misc.hh +++ b/lout/misc.hh @@ -6,6 +6,7 @@ #include #include #include +#include "dlib/dlib.h" namespace lout { @@ -586,7 +587,7 @@ public: * A copy is kept in the buffer, so the caller does not have to care * about memory management. */ - inline void append(const char *str) { appendNoCopy(strdup(str)); } + inline void append(const char *str) { appendNoCopy(dStrdup(str)); } inline void appendInt(int n) { char buf[32]; sprintf (buf, "%d", n); append (buf); } inline void appendPointer(void *p) diff --git a/lout/object.cc b/lout/object.cc index e4e0152a4..5c2ee4333 100644 --- a/lout/object.cc +++ b/lout/object.cc @@ -20,6 +20,7 @@ #include "object.hh" +#include "dlib/dlib.h" #include #include #include @@ -83,7 +84,7 @@ const char *Object::toString() /** \todo garbage! */ misc::StringBuffer sb; intoStringBuffer(&sb); - char *s = strdup(sb.getChars()); + char *s = dStrdup(sb.getChars()); return s; } @@ -291,7 +292,7 @@ void ConstString::intoStringBuffer(misc::StringBuffer *sb) // String // ------------ -String::String (const char *str): ConstString (str ? strdup(str) : NULL) +String::String (const char *str): ConstString (str ? dStrdup(str) : NULL) { } diff --git a/src/css.cc b/src/css.cc index 4dd1127e3..7aa339cf2 100644 --- a/src/css.cc +++ b/src/css.cc @@ -91,7 +91,7 @@ void CssPropertyList::apply (CssPropertyList *props) { if (props->ownerOfStrings && (getRef (i)->type == CSS_TYPE_STRING || getRef (i)->type == CSS_TYPE_SYMBOL)) - value.strVal = strdup(value.strVal); + value.strVal = dStrdup(value.strVal); props->set ((CssPropertyName) getRef (i)->name, (CssValueType) getRef (i)->type, diff --git a/src/dialog.cc b/src/dialog.cc index 349280956..ac007315c 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -32,6 +32,7 @@ #include "dialog.hh" #include "misc.h" #include "prefs.h" +#include "dlib/dlib.h" /* * Local Data @@ -190,7 +191,7 @@ const char *a_Dialog_input(const char *title, const char *msg) source = (char *)dList_nth_data(prefs.search_urls, i); if (!source || a_Misc_parse_search_url(source, &label, &url) < 0) continue; - pm[j++].label(FL_NORMAL_LABEL, strdup(label)); + pm[j++].label(FL_NORMAL_LABEL, dStrdup(label)); } } ch->tooltip("Select search engine"); diff --git a/src/form.cc b/src/form.cc index 8234c0a34..93bd4864d 100644 --- a/src/form.cc +++ b/src/form.cc @@ -19,6 +19,7 @@ #include "dw/core.hh" #include "dw/textblock.hh" +#include "dlib/dlib.h" #include "misc.h" #include "msg.h" #include "prefs.h" @@ -829,7 +830,7 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize) if (!label) { BUG_MSG(" requires label attribute."); - label = strdup(""); + label = dStrdup(""); } DilloHtmlOptgroup *opt = diff --git a/src/tipwin.cc b/src/tipwin.cc index c2f37431f..235e5f565 100644 --- a/src/tipwin.cc +++ b/src/tipwin.cc @@ -27,6 +27,7 @@ #include "prefs.h" #include "tipwin.hh" +#include "dlib/dlib.h" /* * Forward declarations @@ -132,7 +133,7 @@ TipWinButton::TipWinButton(int x, int y, int w, int h, const char *l) : Fl_Button(x, y, w, h, l) { tipwin = my_tipwin(); - mytooltip = strdup("empty"); + mytooltip = dStrdup("empty"); } TipWinButton::~TipWinButton(void) @@ -161,7 +162,7 @@ int TipWinButton::handle(int e) void TipWinButton::set_tooltip(const char *s) { free(mytooltip); - mytooltip = strdup(s); + mytooltip = dStrdup(s); } @@ -209,7 +210,7 @@ TipWinInput::TipWinInput (int x, int y, int w, int h, const char *l) : Fl_Input(x,y,w,h,l) { tipwin = my_tipwin(); - mytooltip = strdup("empty"); + mytooltip = dStrdup("empty"); } TipWinInput::~TipWinInput(void) @@ -239,6 +240,6 @@ int TipWinInput::handle(int e) void TipWinInput::set_tooltip(const char *s) { free(mytooltip); - mytooltip = strdup(s); + mytooltip = dStrdup(s); } diff --git a/test/dw/Makefile.am b/test/dw/Makefile.am index 39bb8440e..d3aff0742 100644 --- a/test/dw/Makefile.am +++ b/test/dw/Makefile.am @@ -10,6 +10,7 @@ LDADD = \ $(top_builddir)/dw/libDw-fltk.a \ $(top_builddir)/dw/libDw-core.a \ $(top_builddir)/lout/liblout.a \ + $(top_builddir)/dlib/libDlib.a \ @LIBFLTK_LIBS@ @LIBX11_LIBS@ check_PROGRAMS = \ diff --git a/test/dw/dw_anchors_test.cc b/test/dw/dw_anchors_test.cc index e88cecb69..258acc0e6 100644 --- a/test/dw/dw_anchors_test.cc +++ b/test/dw/dw_anchors_test.cc @@ -24,6 +24,7 @@ #include #include +#include "dlib/dlib.h" #include "dw/core.hh" #include "dw/fltkcore.hh" #include "dw/fltkviewport.hh" @@ -111,7 +112,7 @@ int main(int argc, char **argv) char buf[16]; strcpy (buf, numbers[i]); buf[0] = lout::misc::AsciiToupper (buf[0]); - buttonLabel[i] = strdup(buf); + buttonLabel[i] = dStrdup(buf); Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]); button->callback (anchorCallback, (void*)(long)i); button->when (FL_WHEN_RELEASE); diff --git a/test/dw/form.cc b/test/dw/form.cc index 82938a16e..93c65d393 100644 --- a/test/dw/form.cc +++ b/test/dw/form.cc @@ -20,6 +20,7 @@ #include "form.hh" +#include "dlib/dlib.h" namespace form { @@ -27,7 +28,7 @@ using namespace dw::core::ui; Form::ResourceDecorator::ResourceDecorator (const char *name) { - this->name = strdup (name); + this->name = dStrdup (name); } Form::ResourceDecorator::~ResourceDecorator () @@ -58,7 +59,7 @@ Form::RadioButtonResourceDecorator::RadioButtonResourceDecorator n++; this->values = new const char*[n + 1]; for (int i = 0; i < n; i++) - this->values[i] = strdup (values[i]); + this->values[i] = dStrdup (values[i]); this->values[n] = 0; } @@ -108,7 +109,7 @@ Form::SelectionResourceDecorator::SelectionResourceDecorator n++; this->values = new const char*[n + 1]; for(int i = 0; i < n; i++) - this->values[i] = strdup (values[i]); + this->values[i] = dStrdup (values[i]); this->values[n] = 0; } @@ -153,8 +154,8 @@ Form::FormClickedReceiver::FormClickedReceiver (Form *form, const char *name, const char *value) { this->form = form; - this->name = strdup (name); - this->value = strdup (value); + this->name = dStrdup (name); + this->value = dStrdup (value); } Form::FormClickedReceiver::~FormClickedReceiver () diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 67095f36a..bcf3e3cbe 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -27,8 +27,14 @@ EXTRA_DIST = \ hyph-de.pat containers_SOURCES = containers.cc +containers_LDADD = \ + $(top_builddir)/lout/liblout.a \ + $(top_builddir)/dlib/libDlib.a notsosimplevector_SOURCES = notsosimplevector.cc identity_SOURCES = identity.cc +identity_LDADD = \ + $(top_builddir)/lout/liblout.a \ + $(top_builddir)/dlib/libDlib.a cookies_SOURCES = cookies.c cookies_LDADD = \ $(top_builddir)/dpip/libDpip.a \ @@ -36,6 +42,7 @@ cookies_LDADD = \ shapes_SOURCES = shapes.cc shapes_LDADD = \ $(top_builddir)/dw/libDw-core.a \ + $(top_builddir)/dlib/libDlib.a \ $(top_builddir)/lout/liblout.a unicode_test_SOURCES = unicode_test.cc unicode_test_LDADD = \ @@ -47,6 +54,7 @@ liang_LDADD = \ $(top_builddir)/dw/libDw-fltk.a \ $(top_builddir)/dw/libDw-core.a \ $(top_builddir)/lout/liblout.a \ + $(top_builddir)/dlib/libDlib.a \ @LIBFLTK_LIBS@ @LIBX11_LIBS@ trie_SOURCES = trie.cc trie_LDADD = \ @@ -54,4 +62,5 @@ trie_LDADD = \ $(top_builddir)/dw/libDw-fltk.a \ $(top_builddir)/dw/libDw-core.a \ $(top_builddir)/lout/liblout.a \ + $(top_builddir)/dlib/libDlib.a \ @LIBFLTK_LIBS@ @LIBX11_LIBS@ From d3ac1dc41d10858fdd9837ed2826595d0aa4c1db Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 6 Aug 2024 15:14:28 +0200 Subject: [PATCH 12/28] Use POSIX-2001 for C++ too Reviewed-by: dogma --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8d342605c..fef3bfc94 100644 --- a/configure.ac +++ b/configure.ac @@ -664,7 +664,7 @@ dnl ----------- dnl if eval "test x$GCC = xyes"; then - CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-rtti -fno-exceptions -pedantic -std=c++11" + CXXFLAGS="$CXXFLAGS -Wall -W -Wno-unused-parameter -fno-rtti -fno-exceptions -pedantic -std=c++11 -D_POSIX_C_SOURCE=200112L" fi AC_SUBST(BASE_CUR_WORKING_DIR) From 006ab1f9d9c9dd3b76ccdc04aff22de1be151810 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 6 Aug 2024 17:38:05 +0200 Subject: [PATCH 13/28] Use dStrAsciiCasecmp instead of strncasecmp Reviewed-by: dogma --- src/uicmd.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uicmd.cc b/src/uicmd.cc index 03d191ad8..187aeabc6 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -46,6 +46,7 @@ #include "msg.h" #include "prefs.h" #include "misc.h" +#include "dlib/dlib.h" #include "dw/fltkviewport.hh" @@ -704,7 +705,7 @@ static char *UIcmd_find_search_str(const char *str) for (p = 0; p < dList_length(prefs.search_urls); p++) { const char *search = (const char *)dList_nth_data(prefs.search_urls, p); - if (search && strncasecmp(str, search, len) == 0) { + if (search && dStrnAsciiCasecmp(str, search, len) == 0) { prefs.search_url_idx = p; url = UIcmd_make_search_str(str + len + 1); break; From fc3bed2369c12de6e7f4b66420a531e02454eeb6 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 6 Aug 2024 17:51:27 +0200 Subject: [PATCH 14/28] Use d_isascii() instead of isascii() Reviewed-by: dogma Tested-by: Alex (on OpenBSD) --- src/html.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/html.cc b/src/html.cc index b667e5a30..3297796a5 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1486,10 +1486,10 @@ static int int i; for (i = 0; val[i]; ++i) - if (!isascii(val[i]) || !(isalnum(val[i]) || strchr(":_.-", val[i]))) + if (!d_isascii(val[i]) || !(isalnum(val[i]) || strchr(":_.-", val[i]))) break; - if (val[i] || !(isascii(val[0]) && isalpha(val[0]))) + if (val[i] || !(d_isascii(val[0]) && isalpha(val[0]))) BUG_MSG("%s attribute value \"%s\" is not of the form " "'[A-Za-z][A-Za-z0-9:_.-]*'.", attrname, val); From 93d3bf225db8868413f85dc48fe5627c5d159db0 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 Aug 2024 16:35:08 +0200 Subject: [PATCH 15/28] Remove unused init() function --- lout/misc.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lout/misc.cc b/lout/misc.cc index c6e057fa3..72f01047a 100644 --- a/lout/misc.cc +++ b/lout/misc.cc @@ -32,12 +32,6 @@ namespace misc { const char *prgName = PRGNAME; -//void init (int argc, char *argv[]) -//{ -// prgName = dStrdup (argv[0]); -//} - - // ------------------ // StringBuffer // ------------------ From b0522d9d117bbd1e9bb3f94bff4e062a324bfce9 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 Aug 2024 16:39:59 +0200 Subject: [PATCH 16/28] Add entry about portability in ChangeLog Also add missing hyphens on previous entries. --- ChangeLog | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index db8e1ef23..462157a44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,11 +11,13 @@ dillo-3.2.0 [Not released yet] +- Add new_tab_page option to open a custom new tab page. Patches: Alex, Rodrigo Arias Mallo +- Ignore empty page title for tab labels. - Fix segfault when clicking the "Done" button in downloads dialog. - Add zoom support using Ctrl +/-/0 and the "zoom_factor" option. - Fix wrong redirect by meta refresh without URL. - Display JSON as plain text. - Add line number anchors in HTML source view. + - Fix segfault when clicking the "Done" button in downloads dialog. + - Add zoom support using Ctrl +/-/0 and the "zoom_factor" option. + - Fix wrong redirect by meta refresh without URL. + - Display JSON as plain text. + - Add line number anchors in HTML source view. + - Make Dillo strictly C99, C++11 and POSIX-2001 compliant, without depending on + GNU extensions. Patches: Rodrigo Arias Mallo +- Add primitive support for SVG using the nanosvg.h library. Patches: dogma, Rodrigo Arias Mallo From d6e9b4ee89a4ea45eaccf65af03474e0066638ff Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 Aug 2024 16:57:36 +0200 Subject: [PATCH 17/28] Avoid C++11 default keyword While we still require C++11 for the macros, there is no need to add another dependency for this case. Reported-by: dogma --- lout/container.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lout/container.hh b/lout/container.hh index 5bddbe63c..70f3d304c 100644 --- a/lout/container.hh +++ b/lout/container.hh @@ -251,7 +251,7 @@ protected: { object::Object *object; Node *next; - virtual ~Node() = default; + virtual ~Node() {}; }; Node **table; From d156863f8b4a08d0487b22f2ab9ac2d5809539ed Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 Aug 2024 12:25:44 +0200 Subject: [PATCH 18/28] Add GitHub infinite loop HTML render test --- test/html/Makefile.am | 2 ++ test/html/render/github-infinite-loop.html | 14 ++++++++++++++ test/html/render/github-infinite-loop.ref.html | 14 ++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/html/render/github-infinite-loop.html create mode 100644 test/html/render/github-infinite-loop.ref.html diff --git a/test/html/Makefile.am b/test/html/Makefile.am index 80cbcef93..3cac57c61 100644 --- a/test/html/Makefile.am +++ b/test/html/Makefile.am @@ -14,6 +14,7 @@ TESTS = \ render/b-div.html \ render/div-100-percent-with-padding.html \ render/float-img-justify.html \ + render/github-infinite-loop.html \ render/hackernews.html \ render/img-aspect-ratio.html \ render/main-style.html \ @@ -42,6 +43,7 @@ TESTS = \ XFAIL_TESTS = \ render/div-100-percent-with-padding.html \ render/float-img-justify.html \ + render/github-infinite-loop.html \ render/img-aspect-ratio.html \ render/margin-auto.html \ render/max-width-html.html \ diff --git a/test/html/render/github-infinite-loop.html b/test/html/render/github-infinite-loop.html new file mode 100644 index 000000000..62ca64bee --- /dev/null +++ b/test/html/render/github-infinite-loop.html @@ -0,0 +1,14 @@ + + + + GitHub infinite layout loop + + +
+
+ + +
+
+ + diff --git a/test/html/render/github-infinite-loop.ref.html b/test/html/render/github-infinite-loop.ref.html new file mode 100644 index 000000000..cc6bb4e9f --- /dev/null +++ b/test/html/render/github-infinite-loop.ref.html @@ -0,0 +1,14 @@ + + + + GitHub infinite layout loop + + +
+
+ + +
+
+ + From b298347fdcaee0d44b7b0b39f9764fba4cf7415c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 7 Aug 2024 03:28:12 +0200 Subject: [PATCH 19/28] Stop the layouting loop after 1000 iterations Prevents Dillo from hoarding the CPU due to an infinite loop in the layouting. We also return the control to FLTK to update the screen and process events each 100 iterations, to keep the window responsive. It doesn't fix the root cause of the github-infinite-loop test, but it does allow the rendering to finish with no differences with the reference test. --- ChangeLog | 2 ++ dw/layout.cc | 28 +++++++++++++++++++++++----- dw/layout.hh | 2 +- test/html/Makefile.am | 1 - 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 462157a44..fe1e5c78b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ dillo-3.2.0 [Not released yet] - Add line number anchors in HTML source view. - Make Dillo strictly C99, C++11 and POSIX-2001 compliant, without depending on GNU extensions. + - Perform an emergency stop of the layout engine loop after 1000 iterations to + prevent a hang. Patches: Rodrigo Arias Mallo +- Add primitive support for SVG using the nanosvg.h library. Patches: dogma, Rodrigo Arias Mallo diff --git a/dw/layout.cc b/dw/layout.cc index 966536430..ee54e8926 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -307,7 +307,7 @@ Layout::Layout (Platform *platform) layoutImgRenderer = NULL; resizeIdleCounter = queueResizeCounter = sizeAllocateCounter - = sizeRequestCounter = getExtremesCounter = 0; + = sizeRequestCounter = getExtremesCounter = resizeCounter = 0; } Layout::~Layout () @@ -443,6 +443,10 @@ void Layout::setWidget (Widget *widget) addWidget (widget); updateCursor (); + + /* Reset the resizeCounter when we change the top level widget, as we are + * changing to another page */ + resizeCounter = 0; } /** @@ -868,16 +872,30 @@ void Layout::resizeIdle () enterResizeIdle (); - //static int calls = 0; - // There are two commits, 2863:b749629fbfc9 and 4645:ab70f9ce4353, the second // reverting the former. Interrestingly, the second fixes a bug. However, it // should still examined what happens here, and what happens the other calls // to Layout::resizeIdle() which should be still in the queue. (See // Layout::queueResize(), where resizeIdleId is indeed checked.) - while (resizeIdleId != -1) { - _MSG("Layout::resizeIdle calls = %d\n", ++calls); + for (int i = 0; resizeIdleId != -1; i++) { + + /* Prevent infinite resize loop, if we reach this point it is very likely + * there is a bug in the layouting process */ + if (resizeCounter >= 1000) { + MSG_ERR("Emergency layout stop after %d iterations\n", resizeCounter); + MSG_ERR("Please file a bug report with the complete console output\n"); + resizeIdleId = -1; + break; + } + + /* Only allow 100 iterations before returning to redraw the screen. */ + if (i >= 100) { + MSG_WARN("Stopping layout loop after %d iterations\n", resizeCounter); + break; + } + + resizeCounter++; for (typed::Iterator it = queueResizeList->iterator(); it.hasNext (); ) { diff --git a/dw/layout.hh b/dw/layout.hh index aada20690..e2b64901b 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -246,7 +246,7 @@ private: ...Entered) defined here and in Widget. */ int resizeIdleCounter, queueResizeCounter, sizeAllocateCounter, - sizeRequestCounter, getExtremesCounter; + sizeRequestCounter, getExtremesCounter, resizeCounter; void enterResizeIdle () { resizeIdleCounter++; } void leaveResizeIdle () { resizeIdleCounter--; } diff --git a/test/html/Makefile.am b/test/html/Makefile.am index 3cac57c61..5b6643d6d 100644 --- a/test/html/Makefile.am +++ b/test/html/Makefile.am @@ -43,7 +43,6 @@ TESTS = \ XFAIL_TESTS = \ render/div-100-percent-with-padding.html \ render/float-img-justify.html \ - render/github-infinite-loop.html \ render/img-aspect-ratio.html \ render/margin-auto.html \ render/max-width-html.html \ From 32e67009a994fafc257b042c29ffb76aed7dbe7d Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 7 Aug 2024 13:38:42 +0200 Subject: [PATCH 20/28] Disable CSS messages for now Long CSS stylesheets may fill the console output hiding important messages. For now let's disable them, until we improve the mechanism to select which messages should be enabled at runtime. --- src/cssparser.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cssparser.cc b/src/cssparser.cc index 893f595a6..1e5c5731d 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -27,7 +27,8 @@ using namespace dw::core::style; -#define MSG_CSS(A, ...) MSG(A, __VA_ARGS__) +//#define MSG_CSS(A, ...) _MSG(A, __VA_ARGS__) +#define MSG_CSS(A, ...) do {} while(0) #define DEBUG_TOKEN_LEVEL 0 #define DEBUG_PARSE_LEVEL 0 #define DEBUG_CREATE_LEVEL 0 From 8465e4686ff128a40be4807fce481b16c9b38a8e Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 11 Aug 2024 13:16:24 +0200 Subject: [PATCH 21/28] Stick to POSIX make rules Using $< in a non-suffix rule context is a GNUmake idiom Reported-by: Alex --- doc/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile.am b/doc/Makefile.am index 943e70d7d..ae2ccd5d1 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -11,6 +11,6 @@ dillo.1: $(srcdir)/dillo.1.in Makefile # Use .in.html instead of .html.in so it is recognized as HTML. user_help.html: $(srcdir)/user_help.in.html Makefile - sed 's/__VERSION__/${VERSION}/g' $< > $@ + sed 's/__VERSION__/${VERSION}/g' $(srcdir)/user_help.in.html > $@ DISTCLEANFILES = dillo.1 user_help.html From 8a360e32ac3136494a494379a6dbbacef6f95da2 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 11 Aug 2024 22:21:59 +0200 Subject: [PATCH 22/28] Round CSS value after applying zoom level When a 1px value is used for the border, any zoom level that makes it smaller makes the resulting size 0, so it disappears. Using round instead leaves more room for zooming out before it disappears. Fixes: https://github.com/dillo-browser/dillo/issues/240 --- src/styleengine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styleengine.cc b/src/styleengine.cc index 6aa99910b..5fe410b66 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -791,7 +791,7 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props, bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) { switch (CSS_LENGTH_TYPE (value)) { case CSS_LENGTH_TYPE_PX: - *dest = (int) (CSS_LENGTH_VALUE (value) * zoom); + *dest = roundInt (CSS_LENGTH_VALUE (value) * zoom); return true; case CSS_LENGTH_TYPE_MM: *dest = roundInt (CSS_LENGTH_VALUE (value) * dpmm * zoom); From 38d1620529866dbf638c6fd8a3e8e438b3c6a43c Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 26 Aug 2024 01:10:16 +0200 Subject: [PATCH 23/28] Avoid searching for boundary in file content Making the boundary string very unlikely to collide with the file to upload allows Dillo to assume it would never be found and avoids the expensive memmem() check. Even if major implementations tend to add several '-' characters to multipart/form-data boundaries, this is not enforced by RFC 2046, so it can be increase to 70 random characters. See: https://lists.mailman3.com/hyperkitty/list/dillo-dev@mailman3.com/thread/VUB5PIOPJZ2VTCVGQPBZMGOYEISTXCFX/ --- src/dialog.cc | 1 + src/form.cc | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/dialog.cc b/src/dialog.cc index ac007315c..0137472b2 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -14,6 +14,7 @@ */ #include // for rint() +#include #include #include diff --git a/src/form.cc b/src/form.cc index 93bd4864d..6e81edf66 100644 --- a/src/form.cc +++ b/src/form.cc @@ -1246,6 +1246,24 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) return DataStr; } +static void generate_boundary(Dstr *boundary) +{ + for (int i = 0; i < 70; i++) { + /* Extracted from RFC 2046, section 5.1.1. */ + static const char set[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "'()+_,-./:=? "; + char s[sizeof " "] = {0}; + + do { + *s = rand(); + } while (!strspn(s, set)); + + dStr_append(boundary, s); + } +} + /** * Generate a boundary string for use in separating the parts of a * multipart/form-data submission. @@ -1253,7 +1271,6 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) char *DilloHtmlForm::makeMultipartBoundary(iconv_t char_encoder, DilloHtmlInput *active_submit) { - const int max_tries = 10; Dlist *values = dList_new(5); Dstr *DataStr = dStr_new(""); Dstr *boundary = dStr_new(""); @@ -1294,15 +1311,8 @@ char *DilloHtmlForm::makeMultipartBoundary(iconv_t char_encoder, } } - /* generate a boundary that is not contained within the data */ - for (int i = 0; i < max_tries && !ret; i++) { - // Firefox-style boundary - dStr_sprintf(boundary, "---------------------------%d%d%d", - rand(), rand(), rand()); - dStr_truncate(boundary, 70); - if (dStr_memmem(DataStr, boundary) == NULL) - ret = boundary->str; - } + generate_boundary(boundary); + ret = boundary->str; dList_free(values); dStr_free(DataStr, 1); dStr_free(boundary, (ret == NULL)); From 7ba398c9019ee2cf2b0b93afe5428eacd77c60d4 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 1 Sep 2024 23:54:53 +0200 Subject: [PATCH 24/28] Restrict boundary to alphanum characters Makes it less likely that server implementations may break due to unexpected boundary characters. It also allows us to avoid quotes around the boundary. --- src/form.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/form.cc b/src/form.cc index 6e81edf66..4a401a917 100644 --- a/src/form.cc +++ b/src/form.cc @@ -1252,8 +1252,7 @@ static void generate_boundary(Dstr *boundary) /* Extracted from RFC 2046, section 5.1.1. */ static const char set[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "'()+_,-./:=? "; + "0123456789"; char s[sizeof " "] = {0}; do { From 8faec1d33e19bf86e2a1131daa48736e91497b67 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 1 Sep 2024 23:46:23 +0200 Subject: [PATCH 25/28] Generate boundary by choosing a random character Instead of rejecting random characters that are not in the boundary character set, draw a random index and select the character at that position. The probability distribution is not perfectly uniform with this method, but reduces the number of calls to rand() by 4 times on average. --- ChangeLog | 2 ++ src/form.cc | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe1e5c78b..5cb66591c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,8 @@ dillo-3.2.0 [Not released yet] Patches: Rodrigo Arias Mallo +- Add primitive support for SVG using the nanosvg.h library. Patches: dogma, Rodrigo Arias Mallo ++- Avoid expensive search for multipart/form-data boundaries. + Patches: Xavier Del Campo Romero, Rodrigo Arias Mallo dillo-3.1.1 [Jun 8, 2024] diff --git a/src/form.cc b/src/form.cc index 4a401a917..2ad743b51 100644 --- a/src/form.cc +++ b/src/form.cc @@ -2,6 +2,7 @@ * File: form.cc * * Copyright 2008 Jorge Arellano Cid + * Copyright 2024 Rodrigo Arias Mallo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1246,20 +1247,23 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) return DataStr; } +/** + * Generate a random boundary. + * + * Using 70 random characters makes the probability that it collides + * with a 1 TiB random file less than 1e-117, so there is no need for + * checking for collisions. */ static void generate_boundary(Dstr *boundary) { - for (int i = 0; i < 70; i++) { - /* Extracted from RFC 2046, section 5.1.1. */ - static const char set[] = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789"; - char s[sizeof " "] = {0}; + /* Extracted from RFC 2046, section 5.1.1. */ + static const char set[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"; + static const size_t n = strlen(set); - do { - *s = rand(); - } while (!strspn(s, set)); - - dStr_append(boundary, s); + for (int i = 0; i < 70; i++) { + int c = (unsigned char) set[rand() % n]; + dStr_append_c(boundary, c); } } From 9b6c641637551a9946ca649c04e0a9fe3d39b05d Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 29 Aug 2024 00:38:12 +0200 Subject: [PATCH 26/28] Fix heap use after free in TLS conn on errors When a error causes the TLS connection to fail and stop, the conn struct is free on Tls_close_by_key(), so writing to conn->in_connect is not correct after that point. The solution is to only set the flag when the it is still valid. Reported-by: Alex Link: https://lists.mailman3.com/hyperkitty/list/dillo-dev@mailman3.com/thread/TY2JYCIPC7IQ32U6VC7ZOV3FVFFOE5K3/ --- ChangeLog | 1 + src/IO/tls_openssl.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5cb66591c..a60b249a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ dillo-3.2.0 [Not released yet] GNU extensions. - Perform an emergency stop of the layout engine loop after 1000 iterations to prevent a hang. + - Fix use-after-free on errors in TLS connection. Patches: Rodrigo Arias Mallo +- Add primitive support for SVG using the nanosvg.h library. Patches: dogma, Rodrigo Arias Mallo diff --git a/src/IO/tls_openssl.c b/src/IO/tls_openssl.c index 3e68e9283..5ad12b8c3 100644 --- a/src/IO/tls_openssl.c +++ b/src/IO/tls_openssl.c @@ -1186,7 +1186,10 @@ static void Tls_connect(int fd, int connkey) if (a_Klist_get_data(conn_list, connkey)) { conn->connecting = FALSE; if (failed) { + conn->in_connect = FALSE; Tls_close_by_key(connkey); + /* conn is freed now */ + conn = NULL; } a_IOwatch_remove_fd(fd, DIO_READ|DIO_WRITE); a_Http_connect_done(fd, failed ? FALSE : TRUE); @@ -1195,7 +1198,8 @@ static void Tls_connect(int fd, int connkey) } } - conn->in_connect = FALSE; + if (conn) + conn->in_connect = FALSE; } static void Tls_connect_cb(int fd, void *vconnkey) From cd8c8cd86eecde0bdc82ec04fd6bbcbb56a68446 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 18 Aug 2024 14:42:59 +0200 Subject: [PATCH 27/28] Switch to HTTPS for Google search Use HTTPS by default, as Google won't redirect to HTTPS on its own. --- dillorc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dillorc b/dillorc index 0b8884665..a52350e0d 100644 --- a/dillorc +++ b/dillorc @@ -176,7 +176,7 @@ search_url="dd DuckDuckGo (https) https://duckduckgo.com/lite/?kp=-1&kd=-1&q=%s" search_url="Wikipedia http://www.wikipedia.org/w/index.php?search=%s&go=Go" search_url="Free Dictionary http://www.thefreedictionary.com/%s" search_url="Startpage (https) https://www.startpage.com/do/search?query=%s" -search_url="Google http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s" +search_url="Google https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s" # If set, dillo will ask web servers to send pages in this language. # This setting does NOT change dillo's user interface. From 4f303337cdf3d86b69918a137db19351cdbae581 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 18 Aug 2024 14:44:22 +0200 Subject: [PATCH 28/28] Fix Google search by adding gbv=1 param If not given, it will cause any search attempt to go to a redirect page, which forces the user to click a small link to go to another search with the gbv=1 param set (along with other tracking parameters). Providing it from the start avoids the hassle. --- dillorc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dillorc b/dillorc index a52350e0d..4345eaba8 100644 --- a/dillorc +++ b/dillorc @@ -176,7 +176,7 @@ search_url="dd DuckDuckGo (https) https://duckduckgo.com/lite/?kp=-1&kd=-1&q=%s" search_url="Wikipedia http://www.wikipedia.org/w/index.php?search=%s&go=Go" search_url="Free Dictionary http://www.thefreedictionary.com/%s" search_url="Startpage (https) https://www.startpage.com/do/search?query=%s" -search_url="Google https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s" +search_url="Google https://www.google.com/search?ie=UTF-8&oe=UTF-8&gbv=1&q=%s" # If set, dillo will ask web servers to send pages in this language. # This setting does NOT change dillo's user interface.