Skip to content

Commit ec88b9a

Browse files
authored
Merge pull request #92 from mike632t/unstable
Fixed segmentation fault in HP12C
2 parents 333c9e1 + ea54101 commit ec88b9a

12 files changed

+45
-37
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ for a particular model or apply a patch to the existing firmware.
306306

307307
* Parallel make only works on Linux.
308308

309+
##### HP 11C + HP 12C + HP 15C + HP 16C
310+
311+
Keyboard test is successful but these models do not pass the self-test.
312+
309313
##### HP 29C
310314

311315
* All 30 registers have continuous memory.

makefile

+4-14
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ _files = `ls makefile makefile.*.[0-9] $(SRC)/makefile $(SRC)/makefile.common $
114114
_source = `ls $(SRC)/*.c $(SRC)/*.c.[0-9] $(SRC)/*.h $(SRC)/*.h.[0-9] $(SRC)/*.in $(SRC)/*.in.[0-9] 2>/dev/null || true`
115115
_data = `ls $(ROM)/$(PROGRAM)*.rom $(ROM)/$(PROGRAM)*.rom.[0-9] $(PRG)/$(PROGRAM)*.dat $(PRG)/$(PROGRAM)*.dat.[0-9] 2>/dev/null || true`
116116
_images = `ls $(SRC)/*.ico $(SRC)/*.ico.[0-9] $(SRC)/*.png $(SRC)/*.png.[0-9] $(SRC)/*.svg $(SRC)/*.svg.[0-9] $(IMG)/*.png $(IMG)/*.png.[0-9] 2>/dev/null || true`
117-
_other = `ls $(SRC)/make.com $(SRC)/make.com.[0-9] *.md *.md.[0-9] .gitignore .gitattributes 2>/dev/null || true`
117+
_other = `ls $(SRC)/make.com $(SRC)/make.com.[0-9] *.md *.md.[0-9] $(SRC)/*.md $(SRC)/*.md.[0-9] $(IMG)/*.md $(IMG)/*.md.[0-9] .gitignore .gitattributes 2>/dev/null || true`
118118

119119
_date = `date +'%Y%m%d%H%M'`
120120

@@ -184,10 +184,8 @@ install:
184184
# Note that Tru64 requires both DESTDIR and prefix to be explicitly defined
185185
# when invoking make.
186186
#
187-
# @if [ -z "$${prefix+x}" ]; then echo "'prefix' NOT defined"; else echo "prefix='$(prefix)'"; fi;
188-
# @if [ -z "$${DESTDIR+x}" ]; then echo "'DESTDIR' NOT defined"; else echo "DESTDIR='$(DESTDIR)'"; fi;
189187

190-
@_unset() { if [ -z "$${prefix+x}" ] && [ -z "$(DESTDIR)" ]; then return 0; else return 1; fi;}; \
188+
@_unset() { if [ -z "$(DESTDIR)$(prefix)" ]; then return 0; else return 1; fi;}; \
191189
_desktop="`echo "$(DESKTOP)" | tr '[:lower:]' '[:upper:]' `"; \
192190
if [ -z "$$_desktop" ]; then \
193191
if [ -d "$$HOME/.local" ]; then \
@@ -211,24 +209,19 @@ install:
211209
_unset && prefix="$$HOME" || true; \
212210
$(MAKE) -s DESTDIR=$(DESTDIR) prefix=$$prefix do_none; \
213211
;; \
214-
"") \
215-
echo "Unable to detect desktop: please specify the DESKTOP (GNOME, KDE, MATE, XFCE, ... or NONE)."; \
216-
;; \
217212
*) \
218213
echo "'DESKTOP=$(DESKTOP)' was not recognised: Try 'make install' instead."; \
219214
;; \
220215
esac;
221216

222217
do_copy: $(BIN)
223218
# No matter what desktop environment we are using (even if it is NONE) we
224-
# need to copy the execuitables to the destination folder
225-
#
226-
# @[ -n "$${VERBOSE+x}" ] && echo "'DESKTOP=$(DESKTOP)' 'DESTDIR=$(DESTDIR)' 'prefix=$(prefix)'"
219+
# need to copy the executable files to the destination folder.
227220
#
228221
@[ -n "$(DESTDIR)" ] || [ -d "$(prefix)" ] || \
229222
{ echo "Please ensure $(prefix) exists (or set DESTDIR for staged install)." >&2; exit 1; }
230223
@mkdir -p "$(DESTDIR)$(prefix)"
231-
@cp $$flags -R $(BIN) "$(DESTDIR)$(prefix)"/ # Fail early if source and destination directories are the same
224+
@cp -R $(BIN) "$(DESTDIR)$(prefix)"/ # Fail early if source and destination directories are the same
232225

233226
do_none: do_copy
234227
# Copy binaries (and saved programs ?) to $(BIN) if no desktop specified.
@@ -242,7 +235,6 @@ do_none: do_copy
242235
#
243236
@[ -n "$${VERBOSE+x}" ] && echo "No desktop option selected" || true
244237
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
245-
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
246238
#
247239
# @cp -R $(PRG)/* "$(DESTDIR)$(prefix)/$(BIN)/"
248240

@@ -255,7 +247,6 @@ do_cde: do_copy
255247
#
256248
@[ -n "$${VERBOSE+x}" ] && echo "Selected CDE desktop environment" || true
257249
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
258-
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
259250
#
260251
# Add program files
261252
@cp -R $(PRG)/* "$(DESTDIR)/$(prefix)/$(BIN)/"
@@ -266,7 +257,6 @@ do_env: do_copy $(SRC)/$(PROGRAM).desktop.in $(SRC)/$(PROGRAM).svg
266257
#
267258
@[ -n "$${VERBOSE+x}" ] && echo "Selected $(DESKTOP) environment" || true
268259
@[ -n "$${VERBOSE+x}" ] && echo "Installing in $(DESTDIR)$(prefix)" || true
269-
# @[ -n "$${VERBOSE+x}" ] && echo "prefix=$(prefix)" || true
270260
#
271261
# Copy desktop files
272262
@mkdir -p "$(DESTDIR)$(prefix)"/share/applications;

src/makefile.common

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ PROGRAM = x11-calc-$(MODEL)
3535
BIN = ../bin
3636

3737
# SHARED sources are model-dependant via HP$(MODEL) #define statements
38-
SHARED = x11-calc.c x11-calc-cpu.c x11-calc-display.c x11-calc-digit.c x11-calc-messages.c x11-calc-button.c x11-keyboard.c
39-
COMMON = x11-calc-switch.c x11-calc-label.c x11-calc-colour.c x11-calc-font.c gcc-wait.c gcc-exists.c
38+
SHARED = x11-calc.c x11-calc-cpu.c x11-calc-display.c x11-calc-digit.c x11-calc-messages.c x11-calc-button.c
39+
COMMON = x11-calc-switch.c x11-calc-label.c x11-calc-colour.c x11-calc-font.c x11-keyboard.c gcc-wait.c gcc-exists.c
4040

4141
CC = cc
4242
DEBUG =

src/x11-calc-button.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@
7777
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
7878
#include <X11/Xutil.h> /* XSizeHints etc. */
7979

80-
#include "x11-calc-switch.h"
80+
#include "x11-calc-messages.h"
8181
#include "x11-calc-label.h"
82+
#include "x11-calc-switch.h"
8283
#include "x11-calc-button.h"
8384

8485
#include "x11-calc.h"
@@ -142,7 +143,7 @@ obutton *h_button_create(int i_index, char c_key,
142143
obutton *h_button; /* Ponter to button. */
143144

144145
/* Attempt to allocate memory for a button. */
145-
if ((h_button = malloc (sizeof(*h_button)))==NULL) v_error(errno, "Memory allocation failed in %s line : %d\n", __FILE__, __LINE__);
146+
if ((h_button = malloc (sizeof(*h_button)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
146147

147148
h_button->index = i_index;
148149
h_button->key = c_key;

src/x11-calc-cpu.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,7 @@ oprocessor *h_processor_create(int *h_rom) /* Create a new processor 'object' */
953953
{
954954
oprocessor *h_processor;
955955
int i_count;
956-
if ((h_processor = malloc(sizeof(*h_processor)))==NULL)
957-
v_error(errno, "Memory allocation failed!"); /* Attempt to allocate memory to hold the processor structure */
956+
if ((h_processor = malloc(sizeof(*h_processor)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
958957
for (i_count = 0; i_count < REGISTERS; i_count++)
959958
h_processor->reg[i_count] = h_register_create((i_count + 1) * -1); /* Allocate storage for the registers */
960959
for (i_count = 0; i_count < MEMORY_SIZE; i_count++)

src/x11-calc-display.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
* and the current position of the display - MT
8484
* - Finally renamed x11-calc-segment to the more correct
8585
* x11-calc-digit - MT
86+
* 18 Apr 24 - Checks for undefined labels when updating indicators
87+
* on the display (fixed segmentation fault) - MT
8688
*
8789
*/
8890

@@ -99,10 +101,11 @@
99101
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
100102
#include <X11/Xutil.h> /* XSizeHints etc. */
101103

102-
#include "x11-calc-font.h"
103-
#include "x11-calc-button.h"
104-
#include "x11-calc-switch.h"
104+
#include "x11-calc-messages.h"
105105
#include "x11-calc-label.h"
106+
#include "x11-calc-switch.h"
107+
#include "x11-calc-button.h"
108+
#include "x11-calc-font.h"
106109

107110
#include "x11-calc.h"
108111

@@ -133,7 +136,7 @@ odisplay *h_display_create(int i_index, int i_left, int i_top, int i_width, int
133136
int i_count, i_offset, i_size;
134137

135138
/* Attempt to allocate memory for a display. */
136-
if ((h_display = malloc(sizeof(*h_display)))==NULL) v_error(errno, "Memory allocation failed!");
139+
if ((h_display = malloc(sizeof(*h_display)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
137140
h_display->index = i_index;
138141

139142
h_display->bezel_position.x = i_left; /* Set properties */
@@ -248,7 +251,7 @@ int i_display_draw(Display* x_display, int x_application_window, int i_screen, o
248251

249252
#if defined(HP10c) || defined(HP11c) || defined(HP12c) || defined(HP15c) || defined(HP16c)
250253
for (i_count = 0; i_count < INDECATORS; i_count++)
251-
i_label_draw(x_display, x_application_window, i_screen, h_display->label[i_count]);
254+
if (!(h_display->label[i_count] == NULL)) i_label_draw(x_display, x_application_window, i_screen, h_display->label[i_count]);
252255
#endif
253256

254257
return (True);
@@ -282,9 +285,12 @@ int i_display_resize(odisplay *h_display, float f_scale) /* Resize display base
282285
#if defined(HP10c) || defined(HP11c) || defined(HP12c) || defined(HP15c) || defined(HP16c)
283286
for (i_count = 0; i_count < INDECATORS; i_count++)
284287
{
285-
h_display->label[i_count]->label_position.x = h_display->label[i_count]->label_position.x * f_scale;
286-
h_display->label[i_count]->label_position.y = h_display->bezel_position.y + h_display->display_position.height - h_small_font->descent;
287-
h_display->label[i_count]->label_position.width = h_display->label[i_count]->label_geometry.width * f_scale;
288+
if (!(h_display->label[i_count] == NULL))
289+
{
290+
h_display->label[i_count]->label_position.x = h_display->label[i_count]->label_position.x * f_scale;
291+
h_display->label[i_count]->label_position.y = h_display->bezel_position.y + h_display->display_position.height - h_small_font->descent;
292+
h_display->label[i_count]->label_position.width = h_display->label[i_count]->label_geometry.width * f_scale;
293+
}
288294
}
289295
#endif
290296
return 0;

src/x11-calc-label.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
4949
#include <X11/Xutil.h> /* XSizeHints etc. */
5050

51+
#include "x11-calc-messages.h"
5152
#include "x11-calc-label.h"
5253
#include "x11-calc-switch.h"
5354
#include "x11-calc-button.h"
@@ -85,7 +86,7 @@ olabel *h_label_create(int i_index, char* s_text, XFontStruct *h_font,
8586
olabel *h_label; /* Ponter to label. */
8687

8788
/* Attempt to allcoate memory for a label. */
88-
if ((h_label = malloc (sizeof(*h_label)))==NULL) v_error(errno, "Memory allocation failed!");
89+
if ((h_label = malloc (sizeof(*h_label)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
8990

9091
h_label->index = i_index;
9192
h_label->text = s_text;

src/x11-calc-messages.c

+2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ This is free software: you are free to change and redistribute it.\n\
7373
There is NO WARRANTY, to the extent permitted by law.\n";
7474

7575
const char * h_err_creating_file = "Can't create '%s'.\n";
76+
const char * h_err_memmory_alloc = "Memory allocation failed in %s line : %d\n";
7677
const char * h_err_ROM = "Empty ROM - no firmware loaded.\n";
7778

79+
7880
#if defined(HEXADECIMAL)
7981
const char * h_msg_opcode = "%1x-%03x %03x ";
8082
const char * h_msg_address = "%03x";

src/x11-calc-messages.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ extern char * h_err_invalid_address;
4343
extern char * h_err_invalid_register;
4444
extern char * h_msg_opcode;
4545
extern char * h_msg_address;
46-
const char * h_msg_negative_offset;
47-
const char * h_msg_positive_offset;
48-
const char * h_msg_rom;
46+
47+
extern char * h_msg_negative_offset;
48+
extern char * h_msg_positive_offset;
49+
extern char * h_msg_rom;
4950

5051
extern char * c_msg_usage;
5152
extern char * h_err_invalid_operand;
@@ -65,4 +66,5 @@ extern char * h_err_display_colour;
6566
extern char * h_err_font;
6667

6768
extern char * h_err_creating_file;
69+
extern char * h_err_memmory_alloc;
6870
extern const char * h_err_ROM;

src/x11-calc-switch.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <X11/Xlib.h> /* XOpenDisplay(), etc. */
4949
#include <X11/Xutil.h> /* XSizeHints etc. */
5050

51+
#include "x11-calc-messages.h"
5152
#include "x11-calc-label.h"
5253
#include "x11-calc-switch.h"
5354
#include "x11-calc-button.h"
@@ -87,7 +88,7 @@ oswitch *h_switch_create(int i_index, char* s_on, char* s_mid, char* s_off,
8788
oswitch *h_switch; /* Ponter to switch. */
8889

8990
/* Attempt to allcoate memory for a switch. */
90-
if ((h_switch = malloc (sizeof(*h_switch)))==NULL) v_error(errno, "Memory allocation failed!");
91+
if ((h_switch = malloc (sizeof(*h_switch)))==NULL) v_error(errno, h_err_memmory_alloc, __FILE__, __LINE__);
9192

9293
h_switch->index = i_index;
9394
h_switch->on = s_on;

src/x11-calc.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@
297297
* ratio - MT
298298
* 14 Apr 24 - Fixed zoom validation and checks that zoom value has
299299
* been specified - MT
300+
* 18 Apr 24 - Checks for undefined labels when updating indicators
301+
* on the display (fixed segmentation fault) - MT
300302
*
301303
* To Do - Fix vertical button shape when zoomed in
302304
* - Parse command line in a separate routine.
@@ -309,8 +311,8 @@
309311

310312
#define NAME "x11-calc"
311313
#define VERSION "0.14"
312-
#define BUILD "0147"
313-
#define DATE "13 Apr 24"
314+
#define BUILD "0148"
315+
#define DATE "18 Apr 24"
314316
#define AUTHOR "MT"
315317

316318
#define INTERVAL 25 /* Number of ticks to execute before updating the display */

src/x11-keyboard.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* x11-keyboard.h - An X11 keyboard class.
33
*
44
* Copyright(C) 2021 MT
5-
*
5+
*
66
* A very simple keyboard 'class' to translate keystrokes into basic ASCII
7-
* character codes using the key definitions in keysymdef.h.
7+
* character codes using the key definitions in keysymdef.h.
88
*
99
* This program is free software: you can redistribute it and/or modify it
1010
* under the terms of the GNU General Public License as published by the

0 commit comments

Comments
 (0)