Skip to content

Commit

Permalink
Native components: Don't allow writeable literal strings (#43)
Browse files Browse the repository at this point in the history
Enforce as compiler options in the native (C++) components.
  • Loading branch information
GabrielDosReis authored Dec 31, 2023
1 parent c18ddc9 commit e231f6e
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 54 deletions.
1 change: 0 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down
17 changes: 12 additions & 5 deletions config/open-axiom.m4
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,18 @@ dnl ---------------------------------
dnl -- OPENAXIOM_CXX_EXTRA_OPTIONS --
dnl ---------------------------------
AC_DEFUN([OPENAXIOM_EXTRA_CXX_OPTIONS], [
oa_extra_cxxflags=
OPENAXIOM_CXX_GROK_OPTION([-Wno-mismatched-tags],[oa_extra_cxxflags])
OPENAXIOM_CXX_GROK_OPTION([-Wno-string-plus-int],[oa_extra_cxxflags])
AC_SUBST(oa_extra_cxxflags)
# Compiler warnings that are irrevocably errors.
oa_enabled_cxx_policies='writable-strings'
for f in $oa_enabled_cxx_policies; do
OPENAXIOM_CXX_GROK_OPTION(["-Werror=$f"])
done
# Compiler warnings that should not be considered.
# These flags should go after enabled policies.
oa_disabled_cxx_policies='mismatched-tags string-plus-int'
for f in $oa_disabled_cxx_policies; do
OPENAXIOM_CXX_GROK_OPTION(["-Wno-$f"])
done
])

dnl ---------------------------------
Expand Down
22 changes: 14 additions & 8 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ OA_DELAYED_FFI_FALSE
OA_DELAYED_FFI_TRUE
OA_BUILD_GCL_FALSE
OA_BUILD_GCL_TRUE
oa_extra_cxxflags
OA_USE_LLVM_FALSE
OA_USE_LLVM_TRUE
oa_use_llvm
Expand Down Expand Up @@ -6430,10 +6429,12 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext


oa_extra_cxxflags=
# Compiler warnings that are irrevocably errors.
oa_enabled_cxx_policies='writable-strings'
for f in $oa_enabled_cxx_policies; do

opt=-Wno-mismatched-tags # mandatory
accumulator=oa_extra_cxxflags # optional
opt="-Werror=$f" # mandatory
accumulator= # optional
if test -z $accumulator; then
accumulator=CXXFLAGS
fi
Expand Down Expand Up @@ -6466,9 +6467,15 @@ printf "%s\n" "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext

done

# Compiler warnings that should not be considered.
# These flags should go after enabled policies.
oa_disabled_cxx_policies='mismatched-tags string-plus-int'
for f in $oa_disabled_cxx_policies; do

opt=-Wno-string-plus-int # mandatory
accumulator=oa_extra_cxxflags # optional
opt="-Wno-$f" # mandatory
accumulator= # optional
if test -z $accumulator; then
accumulator=CXXFLAGS
fi
Expand Down Expand Up @@ -6501,8 +6508,7 @@ printf "%s\n" "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext



done

if test x$oa_include_gcl = xyes; then
OA_BUILD_GCL_TRUE=
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down
1 change: 0 additions & 1 deletion src/algebra/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down
1 change: 0 additions & 1 deletion src/boot/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gui.pro.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ LIBS += $$OA_LIB

## C++ compiler
QMAKE_CXX = @CXX@
QMAKE_CXXFLAGS += -std=c++20 @oa_extra_cxxflags@
QMAKE_CXXFLAGS += -std=c++20 @CXXFLAGS@
QMAKE_LINK = @CXX@
2 changes: 1 addition & 1 deletion src/hyper/cond.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using namespace OpenAxiom;
static int check_memostack(TextNode * node);

void
insert_cond(char *label, char *cond)
insert_cond(char *label, const char* cond)
{
CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);

Expand Down
9 changes: 4 additions & 5 deletions src/hyper/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,7 @@ quitHyperDoc()



void
make_window_link(char *name)
void make_window_link(const char* name)
{
if (init_top_window(name) != -1)
{}/* gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; */
Expand Down Expand Up @@ -867,7 +866,7 @@ get_new_window()
val = get_int(spad_socket);
init_scanner();
input_type = SourceInputKind::SpadSocket;
input_string = "";
input_string = nullptr;
gWindow->page = parse_page_from_socket();
gWindow->fAxiomFrame = frame;
XFlush(gXDisplay);
Expand All @@ -886,7 +885,7 @@ get_new_window()
send_int(spad_socket, gWindow->fMainWindow);
init_scanner();
input_type = SourceInputKind::SpadSocket;
input_string = "";
input_string = nullptr;
gWindow->page = parse_page_from_socket();
compute_form_page(gWindow->page);

Expand Down Expand Up @@ -936,7 +935,7 @@ get_new_window()
set_window(wid);
init_scanner();
input_type = SourceInputKind::SpadSocket;
input_string = "";
input_string = nullptr;
gWindow->page = parse_page_from_socket();
display_page(gWindow->page);
gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
Expand Down
2 changes: 1 addition & 1 deletion src/hyper/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern void helpForHyperDoc();
extern void quitHyperDoc();
extern void exitHyperDoc();
extern void mainEventLoop();
extern void make_window_link(char*);
extern void make_window_link(const char* );

extern Window gActiveWindow;
extern int gNeedIconName;
Expand Down
5 changes: 4 additions & 1 deletion src/hyper/htinp.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ make_input_file_list()
void
print_paste_line(FILE *pfile,char *str)
{
char *free = "\\free", *bound = "\\bound", *f = free, *b = bound;
const char* free = "\\free";
const char* bound = "\\bound";
const char* f = free;
const char* b = bound;
int justSaw = 0;

for (; *str; str++) {
Expand Down
4 changes: 2 additions & 2 deletions src/hyper/hyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ extern int issue_serverpaste(TextNode * command);
extern void issue_unixcommand(TextNode * node);
extern int issue_unixpaste(TextNode * node);
extern void service_session_socket();
extern void send_lisp_command(char * command);
extern void send_lisp_command(const char* command);
extern void escape_string(char * s);
extern void unescape_string(char * s);
extern char * print_source_to_string1(TextNode * command , int * sizeBuf);
extern char * print_source_to_string(TextNode * command);
extern void change_cond(char * label , char * newcond);
extern int check_condition(TextNode * node);
extern void insert_cond(char * label , char * cond);
extern void insert_cond(char* label , const char* cond);


#ifndef HTADD
Expand Down
2 changes: 1 addition & 1 deletion src/hyper/initx.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ set_name_and_icon()
XWMHints wmhints;
XClassHint ch;

ch.res_name = "HyperDoc";
ch.res_name = const_cast<char*>("HyperDoc"); // FIXME: Use a better API.
ch.res_class = gArgv[0];
for (s = gArgv[0] + strlen(gArgv[0]) - 1; s != gArgv[0]; s--) {
if (*s == '/') {
Expand Down
8 changes: 4 additions & 4 deletions src/hyper/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct IOState {
long fpos, keyword_fpos;
long page_start_fpos;
Token token;
char *input_string;
const char* input_string;
FILE *cfile;
int keyword;
};
Expand All @@ -114,7 +114,7 @@ long keyword_fpos; /* fpos of beginning of most recent keyword */
Token token; /* most recently read token */
TokenType last_token; /* most recently read token for unget_token */
SourceInputKind input_type; /* indicates where to read input */
char *input_string; /* input string read when from_string is true */
const char* input_string = nullptr; /* input string read when from_string is true */
int last_ch; /* last character read, for unget_char */
int last_command; /* the last socket command */
int keyword; /* the last command was a keyword, or a group */
Expand Down Expand Up @@ -351,7 +351,7 @@ int get_char()
line_number++;
return c;
case SourceInputKind::String:
c = (*input_string ? *input_string++ : EOF);
c = (input_string != nullptr and *input_string != '\0' ? *input_string++ : EOF);
if (c == '\n')
line_number++;
return c;
Expand All @@ -363,7 +363,7 @@ int get_char()
return c;
case SourceInputKind::SpadSocket:
AGAIN:
if (*input_string) {
if (input_string != nullptr and *input_string != '\0') {
/* this should never happen for the first character */
c = *input_string++;
if (c == '\n')
Expand Down
2 changes: 1 addition & 1 deletion src/hyper/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern Token token;
extern OpenAxiom::TokenType last_token;
extern int last_ch;
extern SourceInputKind input_type;
extern char *input_string;
extern const char* input_string;
extern FILE *cfile;
extern short int gInSpadsrc;
extern short int gInVerbatim;
Expand Down
11 changes: 3 additions & 8 deletions src/hyper/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ reset_connection()
close(spad_socket->socket);
spad_socket->socket = 0;
spad_socket = NULL;
if (input_string)
input_string[0] = '\0';
input_string = nullptr;
spad_socket->nbytes_pending = 0;
connect_spad();
}
Expand Down Expand Up @@ -228,7 +227,7 @@ format_page(UnloadedPage *ulpage)
/* parse the HyperDoc statements in the given string */

void
parse_from_string(char *str)
parse_from_string(const char *str)
{
OpenAxiom::IOStateManager save_io_state { };
last_ch = NoChar;
Expand Down Expand Up @@ -366,10 +365,6 @@ parse_page(HyperDocPage *page)
parse_header(page);
}

char *ExpectedBeginScroll =
"Parser Error: Unexpected new page, expecting a begin scroll\n", *ExpectedEndScroll =
"Parser Error: Unexpected new page, expected an end scroll\n";

/*
* The general HyperDoc parsing function. expects to see anything. This
* function will parse until it sees either: 1) A new page starting 2) An end
Expand Down Expand Up @@ -707,7 +702,7 @@ parse_page_from_socket()

init_scanner();
input_type = SourceInputKind::SpadSocket;
input_string = "";
input_string = nullptr;
cur_spadcom = NULL;
gLinkHashTable = page->fLinkHashTable;
hash_init(
Expand Down
2 changes: 1 addition & 1 deletion src/hyper/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern void display_page(HyperDocPage * page);
extern void init_parse_patch(HyperDocPage * page);
extern void load_page(HyperDocPage * page);
extern void parse_HyperDoc(void );
extern void parse_from_string(char * str);
extern void parse_from_string(const char* str);
extern HyperDocPage * parse_page_from_socket(void );
extern HyperDocPage * parse_page_from_unixfd(void );
extern HyperLink * make_input_window(InputItem * item);
Expand Down
4 changes: 2 additions & 2 deletions src/hyper/spadint.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,8 @@ switch_frames()
send_int(session_server, SwitchFrames);
send_int(session_server, gWindow->fAxiomFrame);
}
void
send_lisp_command(char *command)

void send_lisp_command(const char* command)
{
int ret_val;

Expand Down
2 changes: 1 addition & 1 deletion src/include/pixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

extern int file_exists(char * );
extern FILE * zzopen(char * , const char* );
extern void write_pixmap_file(Display * , int , char * , Window , int , int , int , int );
extern void write_pixmap_file(Display*, int, const char*, Window, int, int, int, int);
extern int read_pixmap_file(Display * , int , char * , XImage * * , int * , int * );


Expand Down
4 changes: 2 additions & 2 deletions src/lib/pixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ zzopen(char *file, const char* mode)
********************************************************************/
void
write_pixmap_file(Display *dsp, int scr, char *fn,
write_pixmap_file(Display* dsp, int scr, const char* fn,
Window wid, int x, int y, int width,int height)
{
XImage *xi;
Expand Down Expand Up @@ -301,7 +301,7 @@ read_pixmap_file(Display *display, int screen, char *filename,


void
write_pixmap_file(Display *dsp, int scr, char *fn,
write_pixmap_file(Display* dsp, int scr, const char* fn,
Window wid, int x, int y, int width,int height)
{
XImage *xi;
Expand Down
1 change: 0 additions & 1 deletion src/rt/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down
3 changes: 1 addition & 2 deletions src/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ AM_CXXFLAGS = \
-I. -I$(oa_target_includedir) \
-I$(top_builddir)/config \
-I$(top_srcdir)/src/include \
-DOPENAXIOM_ROOT_DIRECTORY="\"$(open_axiom_installdir)\"" \
@oa_extra_cxxflags@
-DOPENAXIOM_ROOT_DIRECTORY="\"$(open_axiom_installdir)\""

oa_target_oalib = $(oa_target_libdir)/libOpenAxiom.a

Expand Down
4 changes: 1 addition & 3 deletions src/utils/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ oa_enable_checking = @oa_enable_checking@
oa_enable_profiling = @oa_enable_profiling@
oa_enable_threads = @oa_enable_threads@
oa_eval_flags = @oa_eval_flags@
oa_extra_cxxflags = @oa_extra_cxxflags@
oa_host_has_regex = @oa_host_has_regex@
oa_keep_files = @oa_keep_files@
oa_lisp_flavor = @oa_lisp_flavor@
Expand Down Expand Up @@ -442,8 +441,7 @@ AM_CXXFLAGS = \
-I. -I$(oa_target_includedir) \
-I$(top_builddir)/config \
-I$(top_srcdir)/src/include \
-DOPENAXIOM_ROOT_DIRECTORY="\"$(open_axiom_installdir)\"" \
@oa_extra_cxxflags@
-DOPENAXIOM_ROOT_DIRECTORY="\"$(open_axiom_installdir)\""

oa_target_oalib = $(oa_target_libdir)/libOpenAxiom.a
SUFFIXES = .cc .cxx .H .hxx
Expand Down

0 comments on commit e231f6e

Please sign in to comment.