Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Dillo strictly compliant with C90, C++11 and POSIX-2001 #232

Merged
merged 17 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,16 @@ 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
CFLAGS="$CFLAGS -pedantic -std=c99 -D_POSIX_C_SOURCE=200112L"
fi

dnl -----------
dnl CXX options
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 -D_POSIX_C_SOURCE=200112L"
fi

AC_SUBST(BASE_CUR_WORKING_DIR)
Expand Down Expand Up @@ -709,6 +708,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([])
Expand Down
27 changes: 25 additions & 2 deletions dlib/dlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* File: dlib.c
*
* Copyright (C) 2006-2007 Jorge Arellano Cid <[email protected]>
* Copyright (C) 2024 Rodrigo Arias Mallo <[email protected]>
*
* 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
Expand All @@ -24,6 +25,7 @@
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>

#include "dlib.h"

Expand Down Expand Up @@ -883,7 +885,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;

Expand All @@ -901,7 +903,7 @@ char *dGetcwd ()
/**
* Return the home directory in a static string (don't free)
*/
char *dGethomedir ()
char *dGethomedir (void)
{
static char *homedir = NULL;

Expand Down Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions dlib/dlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ 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);
int dUsleep(unsigned long us);

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions dpi/cookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Cookies server.
*
* Copyright 2001 Lars Clausen <[email protected]>
* Jörgen Viksell <[email protected]>
* Jörgen Viksell <[email protected]>
* Copyright 2002-2007 Jorge Arellano Cid <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion dpi/datauri.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "../dpip/dpip.h"
#include "dpiutil.h"
#include "../src/misc.h"

/*
* Debugging macros
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions dpi/downloads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dpi/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions dpid/dpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>

#include <unistd.h>
#include "dpid_common.h"
Expand All @@ -47,7 +49,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);
Expand Down Expand Up @@ -112,7 +114,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;
Expand Down Expand Up @@ -526,7 +528,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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -618,7 +620,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;

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -806,7 +808,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);
Expand Down
6 changes: 3 additions & 3 deletions dpid/dpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions dpid/dpid_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/

#include <dirent.h>
#include <stddef.h> /* size_t */
#include <sys/types.h> /* ssize_t */

#include "../dlib/dlib.h"

Expand Down
3 changes: 2 additions & 1 deletion dpid/dpidc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion dpid/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct dp *dpi_attr_list;
Dlist *services_list;
int numsocks;
int srs_fd;
;

// end of fix

Expand Down
3 changes: 1 addition & 2 deletions dpid/misc_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion dw/findtext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


#include "core.hh"
#include "dlib/dlib.h"
#include "../lout/debug.hh"
#include "../lout/msg.h"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions dw/fltkcomplexbutton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +108,7 @@ int ComplexButton::handle(int event) {
value(0);
return 1;
}
/* fallthrough */
default:
return 0;
}
Expand Down
Loading
Loading