]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Get the last bits of time shifting its value
authorpcarana <pc.moreno2099@gmail.com>
Thu, 21 Mar 2019 17:13:33 +0000 (11:13 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 21 Mar 2019 17:13:33 +0000 (11:13 -0600)
src/vrps.c

index 8a0ad10995ed14a80f75ca8e123e7bb30c6d4a0a..39e8374ea8b65a969ba1c95a4360e764753b71bb 100644 (file)
@@ -43,7 +43,7 @@ struct state {
 int
 deltas_db_init(void)
 {
-       int error;
+       int error, shift;
 
        state.base_db = create_delta();
        if (state.base_db == NULL){
@@ -69,14 +69,10 @@ deltas_db_init(void)
         * 'Fields of a PDU')
         */
        state.current_serial = START_SERIAL;
-       /* The downcast takes the LSBs */
-       /*
-        * TODO (review) The result of `time()` is unlikely to fit in a 16-bit
-        * integer.
-        *
-        * (Also: Integer overflow yields undefined behavior.)
-        */
-       state.v0_session_id = time(NULL);
+
+       /* Get the bits that'll fit in session_id */
+       shift = sizeof(time_t) - sizeof(state.v0_session_id);
+       state.v0_session_id = (u_int16_t)((time(NULL) << shift) >> shift);
        /* Minus 1 to prevent same ID */
        state.v1_session_id = state.v0_session_id - 1;