I'm working on PuTTY 0.79. The large code base has revealed some compiler bugs in 12.00.2 and previous versions. Download and unpack the Unix sources into a Project folder 'src'. The single file examples run on unpatched sources. The project must be patched and renamed with the included shell script to compile.
Bug: IDE Project Manager
When adding .c files of the same name in different folders, the extra source files are considered a duplicate and not added to the project. An extra .obj file is added to the PPJ which is not visible in the IDE tree so can only be removed manually.
Example: Add src\config.c and and src\windows\config.c to a project.
Either block duplicates in the OBJ listing or fix the IDE so it can take same names in different folders.
Bug: Compiler
PuTTY uses tertiary ?: in constant initializers. If the 3 items are constants it should evaluate at compile time as a constant but instead it outputs an error.
aes.h(119)
#define AES_GCM_VTABLE(impl_c, impl_display, bits) \
.ssh2_id = bits==192 ? NULL : "aes" #bits "-gcm@openssh.com", \
"c:\Program Files\PellesC\Bin\pocc.exe" -Tx86-coff -std:C17 -Zi -MT -Ob1 -fp:fast -W1 -Gd -Ze -Zx -DHAVE_STRTOUMAX=1 -DHAVE_GCP_RESULTSW=1 -DAPPNAME=PuTTY -DSSH=1 -DSERIAL=1 -DOTHERBACKENDS=1 -I"c:\Program Files\PellesC\Include\Win" -I"c:\Program Files\PellesC\Include" -Isrc -Isrc\windows -Isrc\terminal src\crypto\aes-sw.c
src\crypto\aes-sw.c(1133): error #2069: Initializer for 'ssh_aes128_gcm_sw' must be constant.
src\crypto\aes-sw.c(1133): error #2069: Initializer for 'ssh_aes192_gcm_sw' must be constant.
src\crypto\aes-sw.c(1133): error #2069: Initializer for 'ssh_aes256_gcm_sw' must be constant.
defs.h(218)
#define TYPECHECK(to_check, to_return) \
(sizeof(to_check) ? (to_return) : (to_return))
"c:\Program Files\PellesC\Bin\pocc.exe" -Tx86-coff -std:C17 -Zi -MT -Ob1 -fp:fast -W1 -Gd -Ze -Zx -DHAVE_STRTOUMAX=1 -DHAVE_GCP_RESULTSW=1 -DAPPNAME=PuTTY -DSSH=1 -DSERIAL=1 -DOTHERBACKENDS=1 -I"c:\Program Files\PellesC\Include\Win" -I"c:\Program Files\PellesC\Include" -Isrc -Isrc\windows -Isrc\terminal src\utils\cert-expr.c
src\utils\cert-expr.c(217): error #2069: Initializer for 'operators' must be constant.
Bug: Windows Headers
Include sequence doesn't does not define CRYPTPROTECTMEMORY_BLOCK_SIZE found in dpapi.h
"c:\Program Files\PellesC\Bin\pocc.exe" -Tx86-coff -std:C17 -Zi -MT -Ob1 -fp:fast -W1 -Gd -Ze -Zx -DHAVE_STRTOUMAX=1 -DHAVE_GCP_RESULTSW=1 -DAPPNAME=PuTTY -DSSH=1 -DSERIAL=1 -DOTHERBACKENDS=1 -I"c:\Program Files\PellesC\Include\Win" -I"c:\Program Files\PellesC\Include" -Isrc -Isrc\windows -Isrc\terminal src\windows\utils\cryptoapi.c
src\windows\utils\cryptoapi.c(38): error #2048: Undeclared identifier 'CRYPTPROTECTMEMORY_BLOCK_SIZE' (did you mean: ?).
src\windows\utils\cryptoapi.c(66): error #2048: Undeclared identifier 'CRYPTPROTECTMEMORY_CROSS_PROCESS' (did you mean: ?).
Adding #include <dpapi.h> generates conflicts with wincrypt.h
c:\Program Files\PellesC\Include\Win\dpapi.h(48): error #2119: Redeclaration of '_CRYPTPROTECT_PROMPTSTRUCT', previously declared at c:\Program Files\PellesC\Include\Win\wincrypt.h(3400).
c:\Program Files\PellesC\Include\Win\dpapi.h(53): error #2119: Redeclaration of 'CRYPTPROTECT_PROMPTSTRUCT', previously declared at c:\Program Files\PellesC\Include\Win\wincrypt.h(3400).
c:\Program Files\PellesC\Include\Win\dpapi.h(53): error #2119: Redeclaration of 'PCRYPTPROTECT_PROMPTSTRUCT', previously declared at c:\Program Files\PellesC\Include\Win\wincrypt.h(3405).
c:\Program Files\PellesC\Include\Win\dpapi.h(74): error #2119: Redeclaration of 'CryptProtectData', previously declared at c:\Program Files\PellesC\Include\Win\wincrypt.h(3795).
c:\Program Files\PellesC\Include\Win\dpapi.h(75): error #2119: Redeclaration of 'CryptUnprotectData', previously declared at c:\Program Files\PellesC\Include\Win\wincrypt.h(3796).
Bug: Compiler
Optimize for speed and full debugging produces bad compile.
"c:\Program Files\PellesC\Bin\pocc.exe" -Tx86-coff -std:C17 -Zi -Ot -Ob1 -fp:fast -W1 -Gd -Ze -Zx -DHAVE_STRTOUMAX=1 -DHAVE_GCP_RESULTSW=1 -DAPPNAME=PuTTY -DSSH=1 -DSERIAL=1 -DOTHERBACKENDS=1 -I"c:\Program Files\PellesC\Include\Win" -I"c:\Program Files\PellesC\Include" -Isrc -Isrc\windows -Isrc\terminal src\windows\storage.c
src\windows\storage.c(846): error #3120: [asm] Symbol '@1854' is undefined.
src\windows\storage.c(846): error #3120: [asm] Symbol '@1853' is undefined.
src\windows\storage.c(846): error #3120: [asm] Symbol '@1852' is undefined.
src\windows\storage.c(846): error #3120: [asm] Symbol '@1851' is undefined.
Compiles fine with any of the following: Remove optimization -Ot. Remove debugging -Zi.
Bug: Compiler
x64+AVX2 does not provide intrinsic _addcarry_u64. Similar to _addcarryx_u64. Sources using _addcarry_u64 would require AVX2 if available. _addcarry_u64 wouldn't be needed if Pelles provided an __int128 and __SIZEOF_INT128__ type.
Bug:
x64 compiler halts with internal error. Compiler is running on an i7-2620M which does not support AVX2.
"c:\Program Files\PellesC\Bin\pocc.exe" -Tx64-coff -arch:AVX2 -std:C17 -Zi -MT -Ot -Ob1 -fp:fast -W1 -Gd -Ze -Zx -DHAVE_STRTOUMAX=1 -DHAVE_GCP_RESULTSW=1 -DAPPNAME=PuTTY -DSSH=1 -DSERIAL=1 -DOTHERBACKENDS=1 -I"c:\Program Files\PellesC\Include\Win" -I"c:\Program Files\PellesC\Include" -Isrc -Isrc\windows -Isrc\terminal src\ssh\transport2.c
fatal error: Internal error: get_rule_number().
Compiles fine with AVX or SSE2.
Bug: IDE Debugger
Unable to debug PuTTY project in 12.00.2. One debug format crashes on startup and the other won't leave functional breakpoints.
Linker Debug Information: "Pelles C format" or both crashes on debugger startup. Debugging works on sample project Hello so maybe the PuTTY project is too large.
Linker Debug Information: "COFF" enters the debugger after disabling all breakpoints. Breakpoints in breakpoint window don't work until the breakpoint is turned on in the debugger.
In 11.00.2 the debugger works with "Pelles C format". "COFF" works poorly as described above.
Bug: Compiler
Inline optimization for strcpy in 11.00.2 applies a single offset multiple times leading to wrong memory being written to. The same inline code in 10.00.6 works. The inline code in 12.00.2 is completely different, slower, and works. The bug may persist in 12.00.2 or the advanced code was disabled in 12.00.2 because the 11.00.2 code was so badly broken.
Enclosed is a project Demo-strcpy-inline that demonstrates an inline optimization bug.
Bug: IDE Editor
Find Next is grayed out when Find what is non Blank from dropdown.
Edit, Replace
Note that Find what is blank and Find Next is greyed out.
Select something in the Find what dropdown.
Note that the Find Next is still grayed out.
Type something in Find what and now Find Next is higlighted.