Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DJGPP warnings #120

Open
Lethja opened this issue Aug 11, 2024 · 7 comments
Open

DJGPP warnings #120

Lethja opened this issue Aug 11, 2024 · 7 comments

Comments

@Lethja
Copy link

Lethja commented Aug 11, 2024

Since #119 made it possible to build DJGPP on DOS naively again. GCC reports several warnings.

Native compiler

Reports as gcc version 4.7.1

Unused function

gettod.c:363:13: warning: 'adjust_cpu_clock' defined but not used [-Wunused-function]

Implicit Function Declaration

cpuid.c: In function 'cpu_get_model':
cpuid.c:277:3: warning: implicit declaration of function 'snprintf' [-Wimplicit-function-declaration]
cpuid.c:277:3: warning: incompatible implicit declaration of built-in function 'snprintf' [enabled by default]
cpuid.c: In function 'cpu_get_freq_info1':
cpuid.c:326:3: warning: incompatible implicit declaration of built-in function 'snprintf' [enabled by default]
cpuid.c: In function 'cpu_get_freq_info2':
cpuid.c:344:3: warning: incompatible implicit declaration of built-in function 'snprintf' [enabled by default]
cpuid.c: In function 'cpu_get_brand_info':
cpuid.c:365:3: warning: incompatible implicit declaration of built-in function 'snprintf' [enabled by default]
pcdbug.c: In function 'dbug_dump':
pcdbug.c:2246:8: warning: incompatible implicit declaration of built-in function 'snprintf' [enabled by default]

This warning manifests itself as a build error later when libwatt.a included in an application

Pragmas

pctcp.c:2213:3: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]

Type Limits

misc_str.c: In function 'strltrim':
misc_str.c:254:3: warning: comparison is always true due to limited range of data type [-Wtype-limits]

Cross Compiler

Reports as gcc version 12.2.0

Unused Function

gettod.c:363:13: warning: 'adjust_cpu_clock' defined but not used [-Wunused-function]
  363 | static void adjust_cpu_clock (const struct timeval *tv)
      |             ^~~~~~~~~~~~~~~~

Array Bounds

In file included from ../inc/sys/werrno.h:13,
                 from pcdns.c:37:
In function 'send_query',
    inlined from 'lookup_domain' at pcdns.c:575:10:
../inc/sys/w32api.h:37:29: warning: array subscript 'union sock_type[0]' is partly outside array bounds of '_udp_Socket[1]' {aka 'struct udp_Socket[1]'} [-Warray-bounds]
   37 |   #define W32_NAMESPACE(x)  _w32_ ## x
../inc/sys/whide.h:82:37: note: in expansion of macro 'W32_NAMESPACE'
   82 | #define outsnl                      W32_NAMESPACE (outsnl)
      |                                     ^~~~~~~~~~~~~
pcdns.c:209:7: note: in expansion of macro 'outsnl'
  209 |       outsnl (sock->udp.err_msg);
      |       ^~~~~~
pcdns.c: In function 'lookup_domain':
pcdns.c:496:15: note: object 'sock' of size 1736
  496 |   _udp_Socket sock;
      |               ^~~~
udp_rev.c: In function 'reverse_lookup':
udp_rev.c:156:15: warning: array subscript 'union sock_type[0]' is partly outside array bounds of '_udp_Socket[1]' {aka 'struct udp_Socket[1]'} [-Warray-bounds]
  156 |       if (sock->udp.usr_yield)
      |               ^~
udp_rev.c:108:15: note: object 'dom_sock' of size 1736
  108 |   _udp_Socket dom_sock;
      |               ^~~~~~~~
udp_rev.c:156:15: warning: array subscript 'union sock_type[0]' is partly outside array bounds of '_udp_Socket[1]' {aka 'struct udp_Socket[1]'} [-Warray-bounds]
  156 |       if (sock->udp.usr_yield)
      |               ^~
udp_rev.c:108:15: note: object 'dom_sock' of size 1736
  108 |   _udp_Socket dom_sock;
      |               ^~~~~~~~
@Lethja
Copy link
Author

Lethja commented Aug 11, 2024

Note: configur.sh does not currently build dj_err.exe nor does it use the existing binary to generate build/djgpp/syserr.c or inc/sys/djgpp.err so #114 (5debd9c) was used to generate these files. No significant changes where found between the configur.bat and configur.lua versions of the files and the chances any warnings coming from this change is unlikely.

--- syserr.c	2024-08-11 12:34:46.459171889 +1000
+++ SYSERR.C	2024-08-11 12:37:44.000000000 +1000
@@ -1,6 +1,6 @@
 /*
- * THIS FILE WAS GENERATED BY %WATT_ROOT%\e:/home/mario/git/projects/watt-32/util/dj_err.exe
- * at Sun Aug 11 12:06:01 2024.
+ * THIS FILE WAS GENERATED BY %WATT_ROOT%\c:/watt-32/util/dj_err.exe
+ * at Sun Aug 11 12:37:45 2024.
  * DO NOT EDIT.
  *
  * The Watt-32 'sys_errlist[]' that replaces vendor's 'sys_errlist[]'
@@ -51,7 +51,7 @@
 char __syserr038[] = "No more files (ENMFILE)";
 char __syserr039[] = "Too many levels of symbolic links (ELOOP)";
 char __syserr040[] = "Value too large (EOVERFLOW)";
-char __syserr041[] = "Invalid or incomplete multibyte or wide character (EILSEQ)";
+char __syserr041[] = "Multibyte/wide character encoding error (EILSEQ)";
 char __syserr042[] = "Operation would block (EWOULDBLOCK)";
 char __syserr043[] = "Operation now in progress (EINPROGRESS)";
 char __syserr044[] = "Operation already in progress (EALREADY)";
--- djgpp.err	2024-08-11 12:35:23.528344479 +1000
+++ DJGPP.ERR	2024-08-11 12:37:44.000000000 +1000
@@ -2,18 +2,18 @@
 #define __SYS_WERRNO_ERR
 
 /*
- * THIS FILE WAS GENERATED BY %WATT_ROOT%\e:/home/mario/git/projects/watt-32/util/dj_err.exe
- * at Sun Aug 11 12:06:01 2024.
+ * THIS FILE WAS GENERATED BY %WATT_ROOT%\c:/watt-32/util/dj_err.exe
+ * at Sun Aug 11 12:37:45 2024.
  * DO NOT EDIT.
  *
- * Watt-32 errnos are after vendor's errnos (1 - 41)
+ * Watt-32 errnos are after vendor's errnos (1 - 38)
  */
 
 #ifndef __DJGPP__
 #error This file is only for use by "__DJGPP__"
 #endif
 
-#define ERRNO_VENDOR_VERSION  "2.05"
+#define ERRNO_VENDOR_VERSION  "2.03"
 
 #define EDOM              1
 #define ERANGE            2

@Lethja
Copy link
Author

Lethja commented Aug 11, 2024

Looks like the pragma warning comes from that very code trying to cover up another warning

Watt-32/src/pctcp.c

Lines 2206 to 2230 in 7482848

/*
* Make this 'gcc' warning go away:
* In function 'tcp_opt_md5_sign',
* pctcp.c:2177:10: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
*/
#if !defined(__clang__)
W32_GCC_PRAGMA (GCC diagnostic push) \
W32_GCC_PRAGMA (GCC diagnostic ignored "-Wstringop-overflow=")
#endif
static __inline int tcp_opt_md5_sign (BYTE *opt)
{
*opt++ = TCPOPT_SIGNATURE; /* option: 19,length,MD5-signature,NOP,NOP */
*opt++ = 2+TCPOPT_SIGN_LEN;
sign_opt = opt; /* remember for finalise_md5_sign() */
opt += TCPOPT_SIGN_LEN;
*opt++ = TCPOPT_NOP;
*opt++ = TCPOPT_NOP;
return (4+TCPOPT_SIGN_LEN);
}
#if !defined(__clang__)
W32_GCC_PRAGMA (GCC diagnostic pop)
#endif

Not exactly sure what tcp_opt_md5_sign() is writing into the opt pointer but it should be possible to write as an array to remove stringop-overflow warning to begin with

@gvanem
Copy link
Owner

gvanem commented Aug 11, 2024

Ok, but gcc 4.7.1 is very old (June 2012 according to this). Yet, it warns on snprint() being a built-in function.
So does it mean djgpp 2.03 doesn't have a prototype for it? (long time since I've had that installed).

On the gcc 12.2.0 (August 2022) warning; I've seen these array-bounds warning elsewhere. But fail to see their importance.
Perhaps it's a false positive?

@Lethja
Copy link
Author

Lethja commented Aug 11, 2024

So does it mean djgpp 2.03 doesn't have a prototype for it? (long time since I've had that installed).

The compiler claims to have __builtin_snprintf() and using it will remove the warning however the more serious problem is that linker will error out later when an application is building against libwatt.a with undefined reference to 'snprintf'. It's worth noting that snprintf() is not part of the C89 standard and there might be other older compilers/linkers/toolchains etc effected by this problem.

My temporary workaround for this build problem was replacing each instance of snprintf() with sprintf() in my DJGPP library build. I haven't tested these specific code paths but looking at each instance the format string seems to always contain a fixed length output. If we assume every number could be up to an unsigned 64bit max then allowing up to 20 characters for each %(l)u makes a buffer overflow with sprintf() impossible:

Watt-32/src/cpuid.c

Lines 275 to 282 in 7482848

id_max = GET_CPUID2 (0, vendor_str2);
snprintf (vendor_str, sizeof(vendor_str), "%.4s%.4s%.4s",
vendor_str2, /* EBX */
vendor_str2+4+4, /* EDX */
vendor_str2+4); /* ECX */
fms = GET_CPUID2 (1, features);

"%.4s%.4s%.4s" <= 13

Watt-32/src/cpuid.c

Lines 324 to 328 in 7482848

ecx = *(DWORD*) &info [2];
snprintf (result, sizeof(result), "Core base: %lu, Core max: %lu, Core bus: %lu (MHz)",
eax & (1 << 15), ebx & (1 << 15), ecx & (1 << 15));
return (result);

"Core base: %lu, Core max: %lu, Core bus: %lu (MHz)" <= 102

Watt-32/src/cpuid.c

Lines 343 to 346 in 7482848

snprintf (result, sizeof(result), "EDX: 0x%08lX, FID: %lu, EffFreqRO: %lu, ProcFeedback: %lu",
edx, (edx & 1), (edx & (1 << 10)), (edx & (1 << 11)));
return (result);

"EDX: 0x%08lX, FID: %lu, EffFreqRO: %lu, ProcFeedback: %lu" <= 112

Watt-32/src/cpuid.c

Lines 363 to 370 in 7482848

eax [2] = GET_CPUID2 (0x80000004, info3);
snprintf (result, sizeof(result),
"%.4s%.12s" "%.4s%.12s" "%.4s%.12s",
(const char*) &eax[0], info1,
(const char*) &eax[1], info2,
(const char*) &eax[2], info3);
return (result);

"%.4s%.12s" "%.4s%.12s" "%.4s%.12s" <= 49

Watt-32/src/pcdbug.c

Lines 2245 to 2248 in 7482848

if (dbg_print_size) /* debug.rx_size = 1 */
snprintf (sz_buf, sizeof(sz_buf), ", size %u",
out ? _eth_last.tx.size : _eth_last.rx.size);
else sz_buf [0] = '\0';

", size %u" <= 28

@sezero
Copy link

sezero commented Aug 11, 2024

So does it mean djgpp 2.03 doesn't have a prototype for it?

djgpp < 2.04 simply doesn't have [v]snprintf(), and naturally doesn't have prototypes of them. That's simply what it's about.

@gvanem
Copy link
Owner

gvanem commented Aug 13, 2024

I haven't tested these specific code paths but looking at each instance the format string seems to always contain
a fixed length output.

I'm okay with assuming that. And replace with sprintf() instead.

@Lethja
Copy link
Author

Lethja commented Aug 24, 2024

I'm not sure whats trying to be achieved with these two variables. sock is declared but doesn't seem to ever be assigned

Watt-32/src/pcdns.c

Lines 495 to 498 in dca78e7

{
_udp_Socket sock;
sock_type *dom_sock = NULL;

Watt-32/src/pcdns.c

Lines 573 to 580 in dca78e7

dom_sock = (sock_type*) &sock;
if (!send_query(dom_sock, q, namebuf, nameserver, qtype))
{
_resolve_timeout = TRUE;
rc = 0;
goto quit; /* doesn't hurt to do sock_close() if udp_open() fails */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants