parallaxinc / Simple-Libraries

Contents of the SimpleIDE workspace folder and its Parallax Learn Simple Libraries subfolder.
http://learn.parallax.com/propeller-c-set-simpleide/update-your-learn-folder
21 stars 21 forks source link

mstimer return value bug #185

Open AndyLindsay opened 5 years ago

AndyLindsay commented 5 years ago

Nice catch from a customer:

The mstime_start function is supposed to return a nonzero number if successful, or zero if unsuccessful, as this screenshot of the documentation shows:

However, I noticed that the code for the function is:

int mstime_start()
{
  mstime_stop();
  cog = 1 + cogstart(ms_timer, NULL, stack, sizeof(stack));
}

which does not have any return statement at the end. I think that the code for this function should instead be:

int mstime_start()
{
  mstime_stop();
  cog = 1 + cogstart(ms_timer, NULL, stack, sizeof(stack));
  return cog;
}
zfi commented 5 years ago

I'm pretty sure that the the function will return the value of the last statement in the function since the function is declared to return a type int. A quick test will verify the behavior. Providing an explicit return does make it much more readable.

Since 'cog' is not declared, I'm assuming that it is defined elsewhere and you are setting it in this function. Otherwise, you could just return the result of the computation and eliminate the variable.