Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
langc
/* In another source file */
#include <string.h>
void copy(char *dst, const char *src) {
  if (!strcpy(dst, src)) {
    /* Report error */
  }
}
 
/* In this source file -- no copy prototype in scope */
void copy();
 
void g(const char *s) {
  char buf[20];
  copy(buf, s, sizeof buf);  /* Violation */
  /* ... */
}

...

Code Block
bgColor#ccccff
langc
/* In another source file */
#include <string.h>
void copy(char *dst, const char *src) {
  if (!strcpy(dst, src) == 0) {
    /* Report error */
  }
}
 
/* Copy prototype in scope in this source file  */
void copy(char *dst, const char *src);
 
void g(const char *s) {
  char buf[20];
  copy(buf, s); 
  /* ... */
}

...

Code Block
bgColor#ccccff
langc
#include <fcntl.h>
 
void func(void) {
  /* ... */
  fd = open(ms, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, file_access_permissions);
  if (fd == -1){
    /* Handle error */
  }
  /* ... */

}

Risk Assessment

Calling a function with incorrect arguments can result in unexpected or unintended program behavior.

...