Skip to content
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

tcpto.c: initialize firstwhen variable #204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mbhangui
Copy link
Contributor

@mbhangui mbhangui commented Jan 9, 2021

Initialize firstwhen variable in tcpto.c and fix compiler warning

Initialize firstwhen variable in tcpto.c and fix compiler warning
tcpto.c Outdated Show resolved Hide resolved
@mbhangui
Copy link
Contributor Author

mbhangui commented Jan 9, 2021

have reduced the scope of the variable

@mbhangui mbhangui requested a review from DerDakon January 9, 2021 14:07
@moon-chilled
Copy link

The compiler warning is wrong—firstwhen will never be used uninitialized—and actually initializing firstwhen obscures that fact.

I think it would be better to refactor the whole loop, if you really want to avoid the warning; something like this maybe:

if (i >= n && n == 0)
  i = -1;
else if (i >= n)
 {
  int firstpos;
  datetime_sec firstwhen;
  record = tcpto_buf;
  firstpos = 0;
  firstwhen = when = extract_record(&record);
  for (i = 1;i < n;++i)
   {
    when = extract_record(&record);
    if ((firstpos < 0) || (when < firstwhen))
     {
      firstpos = i;
      firstwhen = when;
     }
   }
  i = firstpos;
 }

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.

None yet

3 participants