Skip to content

Commit

Permalink
LibC: Remove semicolon in definition of FD_ZERO
Browse files Browse the repository at this point in the history
This causes problems in code of the form

  if (/* condition */)
    FD_ZERO(&thing);
  else
    do_other_thing();

Wrapping the call to memset() in a do/while block fixes the issue.
  • Loading branch information
3541 authored and awesomekling committed Mar 6, 2022
1 parent 7d5d5b3 commit ad1065e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Userland/Libraries/LibC/fd_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#pragma once

#define FD_SETSIZE 1024
#define FD_ZERO(set) memset((set), 0, sizeof(fd_set));
#define FD_ZERO(set) \
do { \
memset((set), 0, sizeof(fd_set)); \
} while (0)
#define FD_CLR(fd, set) ((set)->fds_bits[(fd / 8)] &= ~(1 << (fd) % 8))
#define FD_SET(fd, set) ((set)->fds_bits[(fd / 8)] |= (1 << (fd) % 8))
#define FD_ISSET(fd, set) ((set)->fds_bits[(fd / 8)] & (1 << (fd) % 8))
Expand Down

0 comments on commit ad1065e

Please sign in to comment.