Examples of errors detected by the V692 diagnostic.


V692. An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place.


Wine Is Not an Emulator

V692 An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place. appdefaults.c 390


static void on_remove_app_click(HWND dialog)
{
  ....
  section[strlen(section)] = '\0'; /* remove last backslash  */
  ....
}

'\0' is written to '\0'. Backslash will not be removed.


Linux Kernel

V692 An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place. ipr.c 9409


static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
{
  int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;

  for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
    snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
       "host%d-%d", ioa_cfg->host->host_no, vec_idx);
    ioa_cfg->vectors_info[vec_idx].
      desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
  }
}

Haiku Operation System

V692 An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place. PoorManWindow.cpp 254


void
PoorManWindow::MessageReceived(BMessage* message)
{
  ....
  if (inet_ntop(AF_INET, &sin_addr, addr, sizeof(addr)) != NULL){
    addr[strlen(addr)] = '\0';  // <=
    line << '(' << addr << ") ";
  }
  ....
}

Tizen

V692 An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place. scmirroring_src.c 77


static int __scmirroring_src_send_cmd_to_server(
  scmirroring_src_s *scmirroring, const char *cmd)
{
  int ret = SCMIRRORING_ERROR_NONE;
  char *_cmd = NULL;
  ....
  _cmd = g_strdup(cmd);
  if (_cmd == NULL) {
    scmirroring_error("Out of memory for command buffer");
    return SCMIRRORING_ERROR_OUT_OF_MEMORY;
  }

  _cmd[strlen(_cmd)] = '\0';                           // <=
  ....
}

Similar errors can be found in some other places:

  • V692 An inappropriate attempt to append a null character to a string. To determine the length of a string by 'strlen' function correctly, a string ending with a null terminator should be used in the first place. miracast_server_impl.c 183


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
We use cookies for the analysis of events to improve our content and make user interaction more convenient. By continuing the view of our web-pages you accept the terms of using these files. You can find out more about cookie-files and privacy policy or close the notification, by clicking on the button. Learn More →
Do not show again