ryanbinns / ttwatch

Linux TomTom GPS Watch Utilities
MIT License
207 stars 66 forks source link

Use calloc instead of malloc&memset #111

Closed misdoro closed 7 years ago

misdoro commented 7 years ago

Some cosmetic changes:

Use calloc(1, sizeof(block)) instead of malloc(sizeof(block)) & memset(ptr, 0, sizeof(block)) They are equivalent and calloc seems to be faster on most systems http://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc for example

misdoro commented 7 years ago

Is there any special reason why malloc + memset pair was used?

ryanbinns commented 7 years ago

Not particularly. Habit, probably...

ryanbinns commented 7 years ago

This broke ttwatchd. The copy_options function was using malloc + memcpy to make a copy of the existing structure, not malloc + memset. Changing this to calloc broke it as it no longer made a copy. I have fixed it again.