Commit Graph

129 Commits

Author SHA1 Message Date
Darryl L. Miles d55a2b74ac header file #ifndef guard namespace consistency (global change)
This add an effective namespace prefix to the guard ifndef
2025-07-29 10:50:32 -04:00
Darryl L. Miles 5e17855f31 header file #ifndef guard presence consistency 2025-07-29 10:50:32 -04:00
Darryl L. Miles d13fa6872e MAKE_xxxxx: to skip building OBJs part of configure 2025-07-29 10:50:32 -04:00
Darryl L. Miles 0b29b1cc12 fix GrTextSizePtr API interface return type consistency
commit 86b5d591d from 20241004 by me, modified return type of
GrTextSize API in the graphics from 'void' to 'int' to convey
and error scenario to indicate when 'r' was not filled in for
the caller, but this is a multi graphics driver API interface
so requires all downstream graphics engines to also support
the return type change.

This API can error and indicates when 'Rect *r' was
successfully updated.
2025-07-27 12:45:51 -04:00
Darryl L. Miles 046401cbd8 Use HAVE_SYS_TIME_H and TIME_WITH_SYS_TIME from autoconf where possible 2025-07-27 12:43:04 -04:00
Darryl L. Miles 8d6571066d grMain.c select() usage fix and protect from higher numbered fd's
The old code would only work is the fileno(stream) returned an fd
in the range 0 <= 19.  It would silently fail, if the fd was in
the range 20..1023 because FD_SET() would work and syscall select()
would be limited to only look at the first 20 fd's.  Ignoring any
fd's higher even if set.
This would theoretically cause high CPU usage due to select()
never blocking because there are no active fd's in the fd_set
as far as the kernel interprets the request and the kernel would
immediately return.

But reading the code the 1st argument to select() seems self
limiting for no good reason.  It should be fileno(stream)+1 as
documented in man select(2).

Added the assertion as well, because we are trying to allow magic
to use fd's beyond the standard environmental limits.  So it
becomes an assertion condition if the fd is outside the range
0..1023 because the FD_SET() macro will not operate correctly /
undefined-behaviour.

I can't find any user of this func in the codebase right now.

If you look at sim/SimRsim.c and the use of select() there, it is
correctly using select() to wait on a single fd over there.  This
commit changes this code to match this correct usage.
2025-04-09 15:19:25 -04:00
Darryl L. Miles 705b4da105 TxParseString() refactor to 1-arg public form
Only the txCommands.c file needs the 3-arg form locally
2025-02-23 10:24:40 -05:00
Darryl L. Miles 6ed8f17136 textio: create callback typedef cb_textio_input_t 2025-02-23 10:24:40 -05:00
Darryl L. Miles a764fdbbd1 CodeQL MemoryMayNotBeFreed.ql grTCairo1.c GrTCairoPlotSVG()
created use of 'alloc' local variable to track when an allocation occurred
so exit path logic is more straight forward for compiler/analyser to see
potential optimisations.

the previous version was probably working just fine
2025-02-22 21:35:23 -05:00
Darryl L. Miles 38b25c5d34 CodeQL InconsistentNullnessTest.ql ourgl != NULL
ourgl local variable is set to a non-NULL value (first initialization)
in code that is in lines below where it is dereferenced in a loop.
Somewhere in the loop there is a point where the precondition of ourgl
being set to non-null is expected.
ASSERT added.
2025-02-22 21:31:22 -05:00
Darryl L. Miles e88dcba1c5 CodeQL File{MayNot,Never}BeClosed.ql file-handle resource leaks
Guided by CodeQL static code analyser.

FileMayNotBeClosed.ql
FileMayNeverBeClosed.ql

The trick with "if(fp != stdout)" is problematic (to analyser) as
technically 'stdout' can be a global pointer that COULD be modified any
time, so it might have changed between the fopen() and fclose() calls so
the close MAY NEVER occurs (which is problem the analyzer can see).

So local state is maintained as a bool which will also clarify to the
compiler see the intention without concern for external stdout
modification.

Some items appear to be out and out leaks when certain commands are use.
2025-02-22 21:02:49 -05:00
Tim Edwards c4a2a54cb7 Corrected a syntax error in the old (non-Tcl/Tk) grX11su1.c code
that was introduced with a slew of updates back in October, as
noticed and reported (with solution) by J. Schonberg.
2025-02-15 22:20:50 -05:00
Darryl L. Miles 07f9bbe1fb gcc11 -Wall -Wpedantic cleanup 2025-01-06 16:12:11 +00:00
Darryl L. Miles 661b66a143 TCL9: Tcl_InitStubs(version="9.0") 2025-01-04 11:08:01 -05:00
Darryl L. Miles 17fe81107a TCL9: plugin createProc() function signature change ImgLayerCreate()
Tk_ImageType.createProc() uses new Tcl_Size type now.
2025-01-04 11:08:01 -05:00
Darryl L. Miles db7a1fe20a TCL9: Tk_ConfigureWidget() function signature change 2025-01-04 11:08:01 -05:00
Darryl L. Miles 33b9c63c41 TCL9: Tcl_xxxxxxx() API changes around Tcl_SaveResult() 2025-01-04 11:08:01 -05:00
Darryl L. Miles e27b8a9d19 TCL9: CONST84 removal (all current compilers support const keyword)
Legacy compiler support macro provided by TCL from a time when 'const'
did not exist.

This looks like it was put in place around the time of TCL 8.4
(from 2002 until 2013) which introduced APIs with 'const' types,
that were previously non-const.  Probably due to legacy compiler
support across target platforms at the time.

Since the minimum TCL level is hardwired to 8.5 (from 2007 until
2016) it does not seem like that compatiblity is a current
requirement.
2025-01-04 11:08:01 -05:00
Darryl L. Miles 2066077c4e TCL9: CONST removal (all current compilers support const keyword)
Legacy compiler support macro provided by TCL from a time when 'const'
did not exist.
2025-01-04 11:08:01 -05:00
Darryl L. Miles d999e20b73 TCL9: Tk_Offset() macro removal
Modern compiler have support for 'offsetof' keyword.
2025-01-04 11:08:01 -05:00
Darryl L. Miles 60463e31be TCL9: _ANSI_ARGS_ compatibility macro removal 2025-01-04 11:08:01 -05:00
Darryl L. Miles 91bb9935f9 grOGL1.c: use ATTR_UNREACHABLE to help analyser 2025-01-03 09:08:14 +00:00
Darryl L. Miles 586e9f1e36 Lookup() constify WindGetCommandTable() returns 'const'
This commit related to the dynamic creation of data that is used
to parse commands and options via Lookup.

windows/windows.h: Lookup() constify call-site
tcltk/tclmagic.c: Lookup() constify call-site
graphics/W3Dmain.c: Lookup() constify call-site
windows/windSend.c: Lookup() constify call-site
windows/windMain.c: Lookup() constify call-site
windows/windInt.h: Lookup() constify call-site
textio/txMain.c: Lookup() constify call-site
2024-12-26 15:20:58 -05:00
Darryl L. Miles a3dce62887 LookupFull() constify call-site
lef/lefRead.c LookupFull() constify call-site
lef/defRead.c LookupFull() constify call-site
graphics/grDStyle.c: LookupFull() constify call-site
2024-12-26 15:20:58 -05:00
Darryl L. Miles ff412b74d8 K&R graphics/W3Dmain.c: too few args in CIFNameToMask()
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 13:05:14 -05:00
Darryl L. Miles 114ddf1b0c grX11su1.c: GrX11IconUpdate() potential -1 out-of-bound access
SonarCloud
Access of 'char' element in the region at index -1
https://sonarcloud.io/project/issues?open=AZJB163RNGfDNup0Ri4r&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 3a35d4d28d grTOGL1.c: GrTOGLIconUpdate() potential -1 out-of-bound access
SonarCloud
Access of 'char' element in the region at index -1
This was not picked up, even though similar code was.
2024-12-26 13:01:24 -05:00
Darryl L. Miles 89fa935416 grTk1.c: GrTkIconUpdate() potential -1 out-of-bound access
SonarCloud
Access of 'char' element in the region at index -1
This was not picked up, even though similar code was.
2024-12-26 13:01:24 -05:00
Darryl L. Miles ef7f989da6 grTCairo1.c: GrTCairoIconUpdate() potential -1 out-of-bound access
SonarCloud
Access of 'char' element in the region at index -1
This was not picked up, even though similar code was.
2024-12-26 13:01:24 -05:00
Darryl L. Miles 86b5d591d6 grOGL3.c: add GrOGLTextSize() error return
'textrect' is not filled in when GrOGLTextSize() fails.

Add error return and abort groglPutText() easrly on error.

graphics/grOGL3.c:783 Rect textrect;

SonarCloud
The right operand of '+' is a garbage value
https://sonarcloud.io/project/issues?open=AZJB160qNGfDNup0Riv5&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 56317e6583 grOGL3.c: font, The left operand of '==' is a garbage value
SonarCloud
The left operand of '==' is a garbage value
https://sonarcloud.io/project/issues?open=AZJB160qNGfDNup0Riv4&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 55413d6b3a grOGL1.c: GrOGLIconUpdate() potential -1 out-of-bound access
SonarCloud
Access of 'char' element in the region at index -1
https://sonarcloud.io/project/issues?open=AZJB16z6NGfDNup0Rist&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles da80d5c75d grOGL1.c: pipehandler() XEvent processing NULL deref
SonarCloud
Access to field 'w_flags' results in a dereference of a null pointer (loaded from variable 'mw')
https://sonarcloud.io/project/issues?open=AZJB16z6NGfDNup0Risq&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 26d6af464a grDStyle.c: newres, Branch condition evaluates to a garbage value
'newres' initialization is performed the wrong side of the label
to be effective to the code that uses it.

SonarCloud
Branch condition evaluates to a garbage value
https://sonarcloud.io/project/issues?open=AZJB16zUNGfDNup0RiqG&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 60f308826d grDStyle.c: GrLoadStyles() scount, The left operand of '<' is a garbage value
The use of 'scount' in this function looks complex, it seems to be reset to
zero sometimes and incremented at others.  Analysis shows there is a possible
path where is maybe used uninitialized.

Setting to zero seems like a good choice.

SonarCloud
grDStyle.c:514 The left operand of '<' is a garbage value
https://sonarcloud.io/project/issues?open=AZJB16zUNGfDNup0RiqE&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles 4206ed2436 grTOGL3.c: warning: variable 'font' is used uninitialized
grTOGL3.c:230:5: warning: variable 'font' is used uninitialized whenever switch default is taken

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles 4520112a55 grTk3.c: warning: variable 'font' is used uninitialized
grTk3.c:203:5: warning: variable 'font' is used uninitialized whenever switch default is taken

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles 239366d4b6 grTk3.c: warning: suggest parentheses around '-' in operand of '&'
GCC14 -Wall cleanup series [-Wparentheses]
2024-10-09 21:12:55 -04:00
Darryl L. Miles 64772655dc 38 x warning: suggest parentheses around assignment used as truth value
EFdef.c:110:12: warning: suggest parentheses around assignment used as truth value
EFdef.c:154:12: warning: suggest parentheses around assignment used as truth value
EFdef.c:167:12: warning: suggest parentheses around assignment used as truth value
EFflat.c:546:17: warning: suggest parentheses around assignment used as truth value
EFflat.c:798:12: warning: suggest parentheses around assignment used as truth value
EFflat.c:930:13: warning: suggest parentheses around assignment used as truth value
EFflat.c:1152:12: warning: suggest parentheses around assignment used as truth value
EFflat.c:1157:13: warning: suggest parentheses around assignment used as truth value
EFhier.c:84:12: warning: suggest parentheses around assignment used as truth value
EFhier.c:261:12: warning: suggest parentheses around assignment used as truth value
EFhier.c:489:12: warning: suggest parentheses around assignment used as truth value
EFhier.c:682:12: warning: suggest parentheses around assignment used as truth value
EFname.c:325:12: warning: suggest parentheses around assignment used as truth value
EFname.c:584:13: warning: suggest parentheses around assignment used as truth value
EFname.c:632:16: warning: suggest parentheses around assignment used as truth value
EFname.c:765:16: warning: suggest parentheses around assignment used as truth value
EFname.c:977:12: warning: suggest parentheses around assignment used as truth value
EFsym.c:113:13: warning: suggest parentheses around assignment used as truth value
EFsym.c:164:9: warning: suggest parentheses around assignment used as truth value
EFvisit.c:322:12: warning: suggest parentheses around assignment used as truth value
EFvisit.c:627:12: warning: suggest parentheses around assignment used as truth value
EFvisit.c:881:16: warning: suggest parentheses around assignment used as truth value
EFvisit.c:917:12: warning: suggest parentheses around assignment used as truth value
grTk1.c:1325:9: warning: suggest parentheses around assignment used as truth value
grTk1.c:1342:9: warning: suggest parentheses around assignment used as truth value
grTk1.c:1757:9: warning: suggest parentheses around assignment used as truth value
grTk1.c:1766:9: warning: suggest parentheses around assignment used as truth value
grTk5.c:177:12: warning: suggest parentheses around assignment used as truth value
grTOGL1.c:1095:9: warning: suggest parentheses around assignment used as truth value
grTOGL1.c:1111:9: warning: suggest parentheses around assignment used as truth value
grTOGL1.c:1542:13: warning: suggest parentheses around assignment used as truth value
grTOGL1.c:1551:13: warning: suggest parentheses around assignment used as truth value
grTOGL5.c:201:12: warning: suggest parentheses around assignment used as truth value
grTCairo1.c:1093:13: warning: suggest parentheses around assignment used as truth value
grTCairo1.c:1109:13: warning: suggest parentheses around assignment used as truth value
grTCairo1.c:1493:21: warning: suggest parentheses around assignment used as truth value
grTCairo1.c:1502:21: warning: suggest parentheses around assignment used as truth value
grTCairo5.c:202:16: warning: suggest parentheses around assignment used as truth value

GCC14 -Wall cleanup series [-Wparentheses]
2024-10-09 21:12:55 -04:00
Darryl L. Miles 967b41343b GCC14: warning: missing braces around initializer
GCC14 -Wall cleanup series [-Wmissing-braces]
2024-10-09 21:12:55 -04:00
Darryl L. Miles 65a0dc45dc graphics: windowname[] potential buffer overrun warning
GCC14 loud default warnings series
2024-10-09 20:39:12 -04:00
Darryl L. Miles 54f49829f2 graphics: multiple definition of `various_x11_symbols'
Solution is to make the grX11thread.c and grX11su1[5].c versions
the official location.  Another solution maybe to split them into
their own file grX11common.c that would be shared.

Multiple configurations tested, tested configurations assume X11
is available.  The configuration wording indicates X11 must be
available for all graphics enabled build configurations.

Affected symbols appear to have multiple definitions:
grCursors
grXdpy
grXscrn
pipeRead
pipeWrite
Xhelper
grVisual

GCC14 and linker will not link the final executable due to this.

GCC14 --without-tk --without-tcl
Related issue: https://github.com/RTimothyEdwards/magic/issues/323
2024-10-09 20:35:19 -04:00
Darryl L. Miles e5c3e703c3 HashLookOnly(): passing argument 2 of 'HashLookOnly' makes pointer from integer without a cast
Also HashFind()

GCC14 --without-tk --without-tcl
Related issue: https://github.com/RTimothyEdwards/magic/issues/323
2024-10-09 20:35:19 -04:00
Tim Edwards dba6f99d93 Updated the revision number to go along with the merge of pull
request #325 from Daryl Miles.  Made a few simple style changes
to conform to (what is vaguely defined as) the overall programming
style for magic (passed down from John Ousterhout).
2024-10-01 12:56:31 -04:00
Darryl L. Miles 18a4dddc2b fix: read of uninitialized data at inChar[0]
This is a defensive fix, might cause unexpected program exit if triggered.
The loop will iterate at least once when nbytes==0, but this value
indicates XLookupString did not fill in any data, so the entire buffer
is undefined.

Using memset() before or inChar[0]=0 after XLookupString did not fix
the issue.  Using inChar[0]=0 immediately before the loop did fix as
well.  But this patch seems to be the best approach.
2024-10-01 12:43:27 -04:00
Darryl L. Miles 60fe6427da graphics/grX11su1.c: Dereference of null pointer
Looks like the code below requires w!=NULL to do anything useful.
So when w==NULL we don't continue processing X11 Event.

SonarCloud
graphics/grX11su1.c:895 Dereference of null pointer
https://sonarcloud.io/project/issues?open=AZJB163RNGfDNup0Ri4p&id=dlmiles_magic
2024-10-01 12:36:13 -04:00
Darryl L. Miles 01f9f2246b graphics/grX11su1.c: Dereference of null pointer
Looks like the code below requires w!=NULL to do anything useful.
So when w==NULL we don't continue processing X11 Event.

SonarCloud
graphics/grX11su1.c:842 Dereference of null pointer
https://sonarcloud.io/project/issues?open=AZJB163RNGfDNup0Ri4o&id=dlmiles_magic
2024-10-01 12:36:13 -04:00
Darryl L. Miles 29ee094074 graphics/grOGL1.c Dereference of null pointer
Looks like the code below requires mw!=NULL to do anything useful.
So when mw==NULL we don't continue processing X11 Event.

SonarCloud
graphics/grOGL1.c:563 Dereference of null pointer
https://sonarcloud.io/project/issues?open=AZJB16z6NGfDNup0Riss&id=dlmiles_magic
2024-10-01 12:36:13 -04:00
Darryl L. Miles be258c6557 graphics/grOGL1.c: non-void function does not return a value
Making oglSetProjection() return void, like toglSetProjection()

SonarCloud
graphics/grOGL1.c:408 non-void function does not return a value
https://sonarcloud.io/project/issues?open=AZJB16z6NGfDNup0Riro&id=dlmiles_magic
2024-10-01 12:36:13 -04:00
Darryl L. Miles ae0cdd9fea graphics/grClip.c Branch condition evaluates to a garbage value
This is technically a false positive as grClipPoints() will always
initializes a value to ok1 and ok2 when called.  The function is in
the same compile unit, so probably the compiler can see this as well
and potentially not perform the initiailization begin performed in
this commit.

But to quieten and remove this item from the analysis report
assigning an initialization value.

SonarCloud
graphics/grClip.c:451 Branch condition evaluates to a garbage value
https://sonarcloud.io/project/issues?open=AZJB160MNGfDNup0Rit4&id=dlmiles_magic
2024-10-01 12:36:13 -04:00