Skip to content

Change get_timestamp() return type to int64_t to support ARMCC #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

LDong-Arm
Copy link

time_t NTPClient::get_timestamp() returns negative values on errors, which is fine with GCC_ARM whose time_t is 64-bit integer. But the Arm Compiler's time_t is 32-bit unsigned integer, in ac6/include/time.h:

typedef unsigned int time_t;     /* date/time in unix secs past 1-Jan-70 */

When an error is reported, the value that gets returned with ARMCC is something like year 2100 and the caller cannot catch it.

To resolve this, change the return type of NTPClient::get_timestamp() to int64_t.
Note: This is a breaking change for applications compiled with the Arm Compiler. Callers should store the return value to a 64-bit integer, check the value, then cast it to time_t.

Copy link

@evedon evedon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of get_timestamp assumes that negative numbers are returned for errors so we need to ensure that the returned type is signed.

@LDong-Arm
Copy link
Author

@evedon Thanks for the review.
@0xc0170 As far as I know this library is used by some existing projects. This commit should be non-breaking for GCC_ARM (whose time_t is indirectly typedef'd to 64-bit signed integer), but in any case they should point to an existing SHA1 to avoid breakage?
Also, Travis failed with

$ git merge $TRAVIS_COMMIT
merge: e1681818e500c473e228edebdf60333c1fb51ce4 - not something we can merge
The command "git merge $TRAVIS_COMMIT" exited with 1.

which looks like a CI issue?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 23, 2020

I've missed this earlier. Yes, the travis config is way to old.

@LDong-Arm
Copy link
Author

LDong-Arm commented Nov 23, 2020

I'm kind of inclined to change the API to

// Writes time to *time, returns true if suceeded
bool NTPClient::get_timestamp(time_t *time);

// Deprecated due to lack of error reporting, kept for compatibility
time_t NTPClient::get_timestamp();

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2020

@LDong-Arm if you rebase, I removed travis from this component. This shall be tested via application (as it can by its own), the way it was set up was using unsupported example. We should test but differently. I'll create an issue now with details.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2020

@LDong-Arm if you rebase, I removed travis from this component. This shall be tested via application (as it can by its own), the way it was set up was using unsupported example. We should test but differently. I'll create an issue now with details.

created #16

@LDong-Arm
Copy link
Author

@0xc0170 @evedon I've created #18 to change the API (as said previously), while keeping the old version of get_timestamp() for backward compatibility. I'm closing this one.

@LDong-Arm LDong-Arm closed this Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants