Commit b2d442ee authored by Gerard Marull-Paretas's avatar Gerard Marull-Paretas Committed by Carles Cufi
Browse files

shell: fix MISRA 5.7 violations on `struct tm`



s/struct tm *tm/struct tm *t/ to fix MISRA 5.7 rule violation
(uniqueness of tag identifiers).

Signed-off-by: default avatarGerard Marull-Paretas <gerard.marull@nordicsemi.no>
parent 667eeb11
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -14,20 +14,20 @@
#define HELP_NONE      "[none]"
#define HELP_DATE_SET  "[Y-m-d] <H:M:S>"

static void date_print(const struct shell *sh, struct tm *tm)
static void date_print(const struct shell *sh, struct tm *t)
{
	shell_print(sh,
		    "%d-%02u-%02u "
		    "%02u:%02u:%02u UTC",
		    tm->tm_year + 1900,
		    tm->tm_mon + 1,
		    tm->tm_mday,
		    tm->tm_hour,
		    tm->tm_min,
		    tm->tm_sec);
		    t->tm_year + 1900,
		    t->tm_mon + 1,
		    t->tm_mday,
		    t->tm_hour,
		    t->tm_min,
		    t->tm_sec);
}

static int get_y_m_d(const struct shell *sh, struct tm *tm, char *date_str)
static int get_y_m_d(const struct shell *sh, struct tm *t, char *date_str)
{
	int year;
	int month;
@@ -67,9 +67,9 @@ static int get_y_m_d(const struct shell *sh, struct tm *tm, char *date_str)
		return -EINVAL;
	}

	tm->tm_year = year - 1900;
	tm->tm_mon = month - 1;
	tm->tm_mday = day;
	t->tm_year = year - 1900;
	t->tm_mon = month - 1;
	t->tm_mday = day;

	return 0;
}
@@ -79,7 +79,7 @@ static int get_y_m_d(const struct shell *sh, struct tm *tm, char *date_str)
 * accept H:M:S, :M:S or ::S where the missing field(s) will be filled in by
 * the previous time state.
 */
static int get_h_m_s(const struct shell *sh, struct tm *tm, char *time_str)
static int get_h_m_s(const struct shell *sh, struct tm *t, char *time_str)
{
	char *endptr;

@@ -87,11 +87,11 @@ static int get_h_m_s(const struct shell *sh, struct tm *tm, char *time_str)
		time_str++;
	} else {
		endptr = NULL;
		tm->tm_hour = strtol(time_str, &endptr, 10);
		t->tm_hour = strtol(time_str, &endptr, 10);
		if (endptr == time_str) {
			return -EINVAL;
		} else if (*endptr == ':') {
			if ((tm->tm_hour < 0) || (tm->tm_hour > 23)) {
			if ((t->tm_hour < 0) || (t->tm_hour > 23)) {
				shell_error(sh, "Invalid hour");
				return -EINVAL;
			}
@@ -106,11 +106,11 @@ static int get_h_m_s(const struct shell *sh, struct tm *tm, char *time_str)
		time_str++;
	} else {
		endptr = NULL;
		tm->tm_min = strtol(time_str, &endptr, 10);
		t->tm_min = strtol(time_str, &endptr, 10);
		if (endptr == time_str) {
			return -EINVAL;
		} else if (*endptr == ':') {
			if ((tm->tm_min < 0) || (tm->tm_min > 59)) {
			if ((t->tm_min < 0) || (t->tm_min > 59)) {
				shell_error(sh, "Invalid minute");
				return -EINVAL;
			}
@@ -122,13 +122,13 @@ static int get_h_m_s(const struct shell *sh, struct tm *tm, char *time_str)
	}

	endptr = NULL;
	tm->tm_sec = strtol(time_str, &endptr, 10);
	t->tm_sec = strtol(time_str, &endptr, 10);
	if ((endptr == time_str) || (*endptr != '\0')) {
		return -EINVAL;
	}

	/* Note range allows for a leap second */
	if ((tm->tm_sec < 0) || (tm->tm_sec > 60)) {
	if ((t->tm_sec < 0) || (t->tm_sec > 60)) {
		shell_error(sh, "Invalid second");
		return -EINVAL;
	}