+
+## 22) Keep Arrays of `struct`s Aligned Horizontally When Initializing
+
+- Arrays of `struct`s are:
+ ```C
+ struct foo_struct {
+ int n;
+ int m;
+ int p;
+ };
+
+ struct foo_struct new_instance[] = {
+ { 1, 2, 3 },
+ { 4, 5, 6 },
+ { 7, 8, 9 },
+ };
+ ```
+- Leave a single space after the opening `{` and before closing `}` of the
+ largest member of the last column.
+- Always leave a single space between the largest member of the current column
+ and the member in the next column.
+- A good example is
+ ```C
+ struct signame {
+ int num;
+ const char *name;
+ };
+
+ static const struct signame signames[] = {
+ { SIGHUP, "HUP" },
+ { SIGINT, "INT" },
+ { SIGQUIT, "QUIT" },
+ { SIGILL, "ILL" },
+ { SIGABRT, "ABRT" },
+ { SIGFPE, "FPE" },
+ { SIGKILL, "KILL" },
+ { SIGSEGV, "SEGV" },
+ { SIGPIPE, "PIPE" },
+ { SIGALRM, "ALRM" },
+ { SIGTERM, "TERM" },
+ { SIGUSR1, "USR1" },
+ { SIGUSR2, "USR2" },
+ { SIGCHLD, "CHLD" },
+ { SIGCONT, "CONT" },
+ { SIGSTOP, "STOP" },
+ { SIGTSTP, "TSTP" },
+ { SIGTTIN, "TTIN" },
+ { SIGTTOU, "TTOU" },
+ #ifdef SIGTRAP
+ { SIGTRAP, "TRAP" },
+ #endif
+ #ifdef SIGIOT
+ { SIGIOT, "IOT" },
+ #endif
+ #ifdef SIGEMT
+ { SIGEMT, "EMT" },
+ #endif
+ #ifdef SIGBUS
+ { SIGBUS, "BUS" },
+ #endif
+ #ifdef SIGSTKFLT
+ { SIGSTKFLT, "STKFLT" },
+ #endif
+ #ifdef SIGCLD
+ { SIGCLD, "CLD" },
+ #endif
+ #ifdef SIGURG
+ { SIGURG, "URG" },
+ #endif
+ #ifdef SIGXCPU
+ { SIGXCPU, "XCPU" },
+ #endif
+ #ifdef SIGXFSZ
+ { SIGXFSZ, "XFSZ" },
+ #endif
+ #ifdef SIGVTALRM
+ { SIGVTALRM, "VTALRM" },
+ #endif
+ #ifdef SIGPROF
+ { SIGPROF, "PROF" },
+ #endif
+ #ifdef SIGWINCH
+ { SIGWINCH, "WINCH" },
+ #endif
+ #ifdef SIGIO
+ { SIGIO, "IO" },
+ #endif
+ #ifdef SIGPOLL
+ { SIGPOLL, "POLL" },
+ #endif
+ #ifdef SIGINFO
+ { SIGINFO, "INFO" },
+ #endif
+ #ifdef SIGLOST
+ { SIGLOST, "LOST" },
+ #endif
+ #ifdef SIGPWR
+ { SIGPWR, "PWR" },
+ #endif
+ #ifdef SIGUNUSED
+ { SIGUNUSED, "UNUSED" },
+ #endif
+ #ifdef SIGSYS
+ { SIGSYS, "SYS" },
+ #endif
+ };
+ ```
+
+## 23) Use `strlcpy()` instead of `strncpy()`
+
+When copying strings always use `strlcpy()` instead of `strncpy()`. The
+advantage of `strlcpy()` is that it will always append a `\0` byte to the
+string.
+
+Unless you have a valid reason to accept truncation you must check whether
+truncation has occurred, treat it as an error, and handle the error
+appropriately.
+
+## 24) Use `strlcat()` instead of `strncat()`
+
+When concatenating strings always use `strlcat()` instead of `strncat()`. The
+advantage of `strlcat()` is that it will always append a `\0` byte to the
+string.
+
+Unless you have a valid reason to accept truncation you must check whether
+truncation has occurred, treat it as an error, and handle the error
+appropriately.
+
+## 25) Use `__fallthrough__` in switch statements
+
+If LXC detects that the compiler is new enough it will tell it to check
+`switch` statements for non-documented fallthroughs. Please always place
+a `__fallthrough__` after a `case` which falls through the next one.
+
+```c
+int lxc_attach_run_command(void *payload)
+{
+ int ret = -1;
+ lxc_attach_command_t *cmd = payload;
+
+ ret = execvp(cmd->program, cmd->argv);
+ if (ret < 0) {
+ switch (errno) {
+ case ENOEXEC:
+ ret = 126;
+ break;
+ case ENOENT:
+ ret = 127;
+ break;
+ }
+ }
+
+ SYSERROR("Failed to exec \"%s\"", cmd->program);
+ return ret;
+}
+```