[glibc] hurd: __adjtime(): struct timeval and time_value_t are not identical.

Samuel Thibault via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e1ca9dea05d879c69cc9772253382f77efe627ef

commit e1ca9dea05d879c69cc9772253382f77efe627ef
Author: Michael Kelly <[email protected]>
Date:   Wed Apr 15 22:18:52 2026 +0200

    hurd: __adjtime(): struct timeval and time_value_t are not identical.
    
    'struct timeval' and 'struct time_value' have different types for the
    microseconds component: int and long int. Casting one to the other
    leads to negative numbers not being preserved properly within the
    called code.
    Message-ID: <[email protected]>

Diff:
---
 sysdeps/mach/hurd/adjtime.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/sysdeps/mach/hurd/adjtime.c b/sysdeps/mach/hurd/adjtime.c
index 915b86da13..9d01533b23 100644
--- a/sysdeps/mach/hurd/adjtime.c
+++ b/sysdeps/mach/hurd/adjtime.c
@@ -28,31 +28,36 @@ __adjtime (const struct timeval *delta, struct timeval *olddelta)
 {
   error_t err;
   mach_port_t hostpriv;
-  struct timeval dummy;
+  time_value_t rpc_delta, rpc_olddelta;
 
   err = __get_privileged_ports (&hostpriv, NULL);
   if (err)
     return __hurd_fail (EPERM);
 
-  if (olddelta == NULL)
-    olddelta = &dummy;
-
   if (delta != NULL)
     {
       if (delta->tv_usec >=  TIME_MICROS_MAX ||
           delta->tv_usec <= -TIME_MICROS_MAX)
        return EINVAL;
+
+      rpc_delta.seconds = delta->tv_sec;
+      rpc_delta.microseconds = delta->tv_usec;
     }
+  else
+    return EINVAL;
 
-  err = __host_adjust_time (hostpriv,
-			    /* `time_value_t' and `struct timeval' are in
-                               fact identical with the names changed.  */
-			    *(time_value_t *) delta,
-			    (time_value_t *) olddelta);
+  err = __host_adjust_time (hostpriv, rpc_delta, &rpc_olddelta);
   __mach_port_deallocate (__mach_task_self (), hostpriv);
 
   if (err)
     return __hurd_fail (err);
+
+  if (olddelta != NULL)
+    {
+      olddelta->tv_sec = rpc_olddelta.seconds;
+      olddelta->tv_usec = rpc_olddelta.microseconds;
+    }
+
   return 0;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.