Skip to content

Commit

Permalink
Clean up. Fix memleak. Better data structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusEdgar committed Aug 7, 2024
1 parent b28be7d commit 8864379
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 129 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ endef
ifdef fortify
FTFYSRC = fortify.c
FTFYHDRS = fortify.h ufortify.h
FTFYFLAG =-DFORTIFY
FTFYFLAG ="-DFORTIFY "
FTFYLINTEXCL = --exclude=fortify.*
endif

SOURCES = src/dintwm.c src/commodity.c $(FTFYSRC)
OBJECTS = $(SOURCES:.c=.o)
CFLAGSSTRICT =-pedantic -std=c11 -ggdb3 $(FTFYFLAG) -O2 -Wall -Wextra -Wformat=2 -Wmissing-include-dirs -Winit-self -Wswitch-default -Wswitch-enum -Wunused-parameter -Wfloat-equal -Wundef -Wshadow -Wlarger-than-1000 -Wunsafe-loop-optimizations -Wbad-function-cast -Wcast-align -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Winvalid-pch -Wvolatile-register-var -Wstrict-aliasing=2 -Wstrict-overflow=2 -Wtraditional-conversion -Wwrite-strings -noixemul -save-temps=obj
CFLAGSSTRICT =-pedantic -std=c11 -ggdb3 $(FTFYFLAG)-O2 -Wall -Wextra -Wformat=2 -Wmissing-include-dirs -Winit-self -Wswitch-default -Wswitch-enum -Wunused-parameter -Wfloat-equal -Wundef -Wshadow -Wlarger-than-1000 -Wunsafe-loop-optimizations -Wbad-function-cast -Wcast-align -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Winvalid-pch -Wvolatile-register-var -Wstrict-aliasing=2 -Wstrict-overflow=2 -Wtraditional-conversion -Wwrite-strings -noixemul -save-temps=obj
CC = m68k-amigaos-gcc
CFLAGS =-std=c11 -Ofast -Wall -Wextra -s -fomit-frame-pointer -noixemul
MAINHEADER = include/dintwm.h include/dintwm_shared.h
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,28 @@ Ketopt.h from https://github.com/attractivechaos/klib is licensed under the MIT/

## SAST Tools

[PVS-Studio](https://pvs-studio.com/en/pvs-studio/?utm_source=github&utm_medium=organic&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code.

Other analyzers used are:
Static analyzers used are:
[splint](https://splint.org/)
[flawfinder](https://github.com/david-a-wheeler/flawfinder)
[cppcheck](https://cppcheck.sourceforge.io/)

Check out the Makefile on how this project uses them.

## Memleak checker

This part I find difficult to check for when compiling for a m68k target (no valgrind).

Settled on [fortify](http://aminet.net/package/dev/c/fortify22) which helped me identify a memory leak.

It can be enabled by building the source with:
```
wget http://aminet.net/dev/c/fortify22.lha
lha x fortify22.lha -w=/tmp
cp /tmp/FORTIFY.CXX fortify.c
cp /tmp/UFORTIFY.H ufortify.h
cp /tmp/FORTIFY.H fortify.h
make strict=true fortify=true all
rm {uf,f}ortify*
```

When running the dintwm binary on AmigaOS, some memory allocation statistics will be displayed hopefully showing no memory leaks.
14 changes: 7 additions & 7 deletions include/commodity.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,28 @@
#define KEY_INCALLGAPS_TXT "rawkey " MOD1 " " MOD2 " numericpad +"
#define KEY_DECALLGAPS_TXT "rawkey " MOD1 " " MOD2 " numericpad --"
#define KEY_TILE_OFF_TXT "rawkey " MOD1 " " MOD2 " o"
#define KEY_CMD_0_TXT "rawkey " MOD1 " " MOD2 " j"
#define KEY_CMD_0_TXT "rawkey " MOD1 " " MOD2 " 0"
#define KEY_CMD_1_TXT "rawkey " MOD1 " " MOD2 " 1"
#define KEY_CMD_2_TXT "rawkey " MOD1 " " MOD2 " 2"
#define KEY_CMD_3_TXT "rawkey " MOD1 " " MOD2 " 3"
#define KEY_CMD_4_TXT "rawkey " MOD1 " " MOD2 " 4"
#define KEY_CMD_5_TXT "rawkey " MOD1 " " MOD2 " k"
#define KEY_CMD_5_TXT "rawkey " MOD1 " " MOD2 " 5"
#define KEY_CMD_6_TXT "rawkey " MOD1 " " MOD2 " 6"
#define KEY_CMD_7_TXT "rawkey " MOD1 " " MOD2 " 7"
#define KEY_CMD_8_TXT "rawkey " MOD1 " " MOD2 " 8"
#define KEY_CMD_9_TXT "rawkey " MOD1 " " MOD2 " 9"
#define KEY_WS_0_TXT "rawkey " MOD1 " " MOD2 " 0"
#define KEY_WS_0_TXT "rawkey " MOD1 " " MOD2 " numericpad 0"
#define KEY_WS_1_TXT "rawkey " MOD1 " " MOD2 " numericpad 1"
#define KEY_WS_2_TXT "rawkey " MOD1 " " MOD2 " numericpad 2"
#define KEY_WS_3_TXT "rawkey " MOD1 " " MOD2 " numericpad 3"
#define KEY_WS_4_TXT "rawkey " MOD1 " " MOD2 " numericpad 4"
#define KEY_WS_5_TXT "rawkey " MOD1 " " MOD2 " 5"
#define KEY_CWS_0_TXT "rawkey " MOD1 " " MOD3 " 0"
#define KEY_WS_5_TXT "rawkey " MOD1 " " MOD2 " numericpad 5"
#define KEY_CWS_0_TXT "rawkey " MOD1 " " MOD3 " numericpad 0"
#define KEY_CWS_1_TXT "rawkey " MOD1 " " MOD3 " numericpad 1"
#define KEY_CWS_2_TXT "rawkey " MOD1 " " MOD3 " numericpad 2"
#define KEY_CWS_3_TXT "rawkey " MOD1 " " MOD3 " numericpad 3"
#define KEY_CWS_4_TXT "rawkey " MOD1 " " MOD3 " numericpad 4"
#define KEY_CWS_5_TXT "rawkey " MOD1 " " MOD3 " 5"
#define KEY_CWS_5_TXT "rawkey " MOD1 " " MOD3 " numericpad 5"
#define KEY_CXM_EXIT_TXT "rawkey " MOD1 " " MOD2 " q"
#define KEY_TAB_NEXT_TXT "rawkey " MOD1 " " MOD2 " tab"

Expand All @@ -169,7 +169,7 @@
static short attachtooltypes(CxObj *broker, struct MsgPort *port, struct DiskObject *diskobj);
static short alloc_opts(const char *tt_optvalue, Ostore *s, size_t i, int subtract);
static void free_opts(void);
static short alloc_bar_item(Bar_Text *b, enum bar_texts x, const char *c);
static short assign_bar_item(Bar_Text *b, enum bar_texts x, const char *c);
static void cleanup(void);

static struct Library *iconbase;
Expand Down
2 changes: 2 additions & 0 deletions include/dintwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <dos/dostags.h>
#include "../include/ketopt.h"
#include "../include/wbar_config.h"
#ifdef FORTIFY
#include "../fortify.h"
#endif

//VERCUT
#define DINTWM_VERSION "VERGIT"
Expand Down
8 changes: 0 additions & 8 deletions include/dintwm_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@
#define DEF_BAR_BP_SEP_TWO_COL 3U // Default bar title backpen color
#define DEF_BAR_BG_COL 3U // Default bar bg color

#define WTSTRING_INIT_SIZE 256U // Allow 128 windows before realloc of wtstring

#define MOD1 "control"
#define MOD2 "lcommand"
#define MOD3 "shift"
Expand Down Expand Up @@ -209,7 +207,6 @@ short spiral(const Arg *arg);
short dwindle(const Arg *arg);
short switcher(const Arg *arg);
short changegaps(const Arg *arg);
//int countwindows(int lock, int assign_winfo);
int countwindows(int lock);
void getactive(void);
int cstring_cmp(const void *a, const void *b);
Expand All @@ -236,7 +233,6 @@ extern long int *current_layout;
extern int exclude_wtype;
extern int include_wtype;
extern long unsigned int auto_interval;
//extern unsigned int current_ws;
extern short backdropped;
extern short tile_off;
extern struct Window *wbw;
Expand Down Expand Up @@ -342,13 +338,9 @@ void time_delay(struct timerequest *tr, const struct timeval *tv);

typedef struct {
short wbwin;
//unsigned int workspace;
enum ws_num workspace;
short skip;
struct Window *wptr;
} Winfo;

Winfo *winfo;

extern int malloc_count;
extern int free_count;
12 changes: 6 additions & 6 deletions include/wbar_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ static struct IntuiText wbartext =
.TopEdge = 4,
.LeftEdge = 0,
.ITextFont = NULL,
.DrawMode = JAM2, //-V2568
.FrontPen = 0, //-V2568
.BackPen = 0, //-V2568
.DrawMode = JAM2,
.FrontPen = 0,
.BackPen = 0,
.IText = NULL,
.NextText = NULL
};
Expand All @@ -37,9 +37,9 @@ static struct Border barb =
{
.TopEdge = 0,
.LeftEdge = 0,
.FrontPen = 1, //-V2568
.BackPen = 0, //-V2568
.DrawMode = JAM1, //-V2568
.FrontPen = 1,
.BackPen = 0,
.DrawMode = JAM1,
.NextBorder = NULL,
.XY = NULL,
.Count = 5
Expand Down
22 changes: 19 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,24 @@ Ketopt.h from https://github.com/attractivechaos/klib is licensed under the MIT/

SAST Tools

PVS-Studio - static analyzer for C, C++, C#, and Java code.

Other analyzers used are: splint flawfinder cppcheck
Static analyzers used are: splint flawfinder cppcheck

Check out the Makefile on how this project uses them.

Memleak checker

This part I find difficult to check for when compiling for a m68k target (no valgrind).

Settled on fortify which helped me identify a memory leak.

It can be enabled by building the source with:

wget http://aminet.net/dev/c/fortify22.lha
lha x fortify22.lha -w=/tmp
cp /tmp/FORTIFY.CXX fortify.c
cp /tmp/UFORTIFY.H ufortify.h
cp /tmp/FORTIFY.H fortify.h
make strict=true fortify=true all
rm {uf,f}ortify*

When running the dintwm binary on AmigaOS, some memory allocation statistics will be displayed hopefully showing no memory leaks.
Loading

0 comments on commit 8864379

Please sign in to comment.