Skip to content

Commit

Permalink
Fix: Fixing isotime_add and add zero padding for isotime [#919]
Browse files Browse the repository at this point in the history
* Add nasl log domain

* Revert `ISOTIME_SIZE` from 19 to 16

Size of 19 was introduced with
f85dbd3.
PR: #252
This broke the nasl_isotime_add function.

* Add zero values at end of iso time

When time in the format like '869-10-02 12:34' or
'869-10-02 12' was given to string2isotime() the
function did not fill up the missing seconds and
minutes with zeroes.

* Fix formatting
  • Loading branch information
ArnoStiefvater authored Nov 2, 2021
1 parent 315ea40 commit e7f4daf
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions nasl/nasl_isotime.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@
#include <time.h>
#include <unistd.h>

#undef G_LOG_DOMAIN
/**
* @brief GLib logging domain.
*/
#define G_LOG_DOMAIN "lib nasl"

#ifndef DIM
#define DIM(v) (sizeof (v) / sizeof ((v)[0]))
#define DIMof(type, member) DIM (((type *) 0)->member)
#endif

/* The type used to represent the time here is a string with a fixed
length. */
#define ISOTIME_SIZE 19
#define ISOTIME_SIZE 16
typedef char my_isotime_t[ISOTIME_SIZE];

/* Correction used to map to real Julian days. */
Expand Down Expand Up @@ -273,11 +279,21 @@ string2isotime (my_isotime_t atime, const char *string)
atime[9] = string[11];
atime[10] = string[12];
if (string[13] != ':')
return 13;
{
atime[11] = '0';
atime[12] = '0';
atime[13] = '0';
atime[14] = '0';
return 13;
}
atime[11] = string[14];
atime[12] = string[15];
if (string[16] != ':')
return 16;
{
atime[13] = '0';
atime[14] = '0';
return 16;
}
atime[13] = string[17];
atime[14] = string[18];
return 19;
Expand Down

0 comments on commit e7f4daf

Please sign in to comment.