Call to gmtime is potentially dangerous (#1598)

* Call to gmtime is potentially dangerous

* Revert "Call to gmtime is potentially dangerous"

This reverts commit cc531e4e19.

* Call to gmtime is potentially dangerous

* oops

* not a pointer

* Little identation fix
old-commit-hash: 3ddbb7fe5b
commatwo_master
Yahya Lmallas 5 years ago committed by GitHub
parent 55dedc0476
commit 8e6224cfd2
  1. 26
      selfdrive/boardd/boardd.cc

@ -230,17 +230,18 @@ bool usb_connect() {
time_t rawtime;
time(&rawtime);
struct tm * sys_time = gmtime(&rawtime);
struct tm sys_time;
gmtime_r(&rawtime, &sys_time);
// Get time from RTC
timestamp_t rtc_time;
libusb_control_transfer(dev_handle, 0xc0, 0xa0, 0, 0, (unsigned char*)&rtc_time, sizeof(rtc_time), TIMEOUT);
//printf("System: %d-%d-%d\t%d:%d:%d\n", 1900 + sys_time->tm_year, 1 + sys_time->tm_mon, sys_time->tm_mday, sys_time->tm_hour, sys_time->tm_min, sys_time->tm_sec);
//printf("System: %d-%d-%d\t%d:%d:%d\n", 1900 + sys_time.tm_year, 1 + sys_time.tm_mon, sys_time.tm_mday, sys_time.tm_hour, sys_time.tm_min, sys_time.tm_sec);
//printf("RTC: %d-%d-%d\t%d:%d:%d\n", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);
// Update system time from RTC if it looks off, and RTC time is good
if (1900 + sys_time->tm_year < 2019 && rtc_time.year >= 2019){
if (1900 + sys_time.tm_year < 2019 && rtc_time.year >= 2019){
LOGE("System time wrong, setting from RTC");
struct tm new_time = { 0 };
@ -472,18 +473,19 @@ void can_health(PubMaster &pm) {
time_t rawtime;
time(&rawtime);
struct tm * sys_time = gmtime(&rawtime);
struct tm sys_time;
gmtime_r(&rawtime, &sys_time);
// Write time to RTC if it looks reasonable
if (1900 + sys_time->tm_year >= 2019){
if (1900 + sys_time.tm_year >= 2019){
pthread_mutex_lock(&usb_lock);
libusb_control_transfer(dev_handle, 0x40, 0xa1, (uint16_t)(1900 + sys_time->tm_year), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa2, (uint16_t)(1 + sys_time->tm_mon), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa3, (uint16_t)sys_time->tm_mday, 0, NULL, 0, TIMEOUT);
// libusb_control_transfer(dev_handle, 0x40, 0xa4, (uint16_t)(1 + sys_time->tm_wday), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa5, (uint16_t)sys_time->tm_hour, 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa6, (uint16_t)sys_time->tm_min, 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa7, (uint16_t)sys_time->tm_sec, 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa1, (uint16_t)(1900 + sys_time.tm_year), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa2, (uint16_t)(1 + sys_time.tm_mon), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa3, (uint16_t)sys_time.tm_mday, 0, NULL, 0, TIMEOUT);
// libusb_control_transfer(dev_handle, 0x40, 0xa4, (uint16_t)(1 + sys_time.tm_wday), 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa5, (uint16_t)sys_time.tm_hour, 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa6, (uint16_t)sys_time.tm_min, 0, NULL, 0, TIMEOUT);
libusb_control_transfer(dev_handle, 0x40, 0xa7, (uint16_t)sys_time.tm_sec, 0, NULL, 0, TIMEOUT);
pthread_mutex_unlock(&usb_lock);
}
}

Loading…
Cancel
Save