0

问题很简单:这段代码有什么问题?

  size_t  buff = 1;
  size_t  new_buff;
  WCHAR   *var_path;
  WCHAR   *dir_path;

  var_path = new WCHAR[buff];
  new_buff = GetEnvironmentVariableW(L"APPDATA", var_path, buff);

  if (new_buff == 0) {
    return 1;
  } else if (new_buff > buff) {
    delete[] var_path;

    var_path = new WCHAR[new_buff];
    GetEnvironmentVariableW(L"APPDATA", var_path, new_buff);
  }

  dir_path = new WCHAR[new_buff];
  wcscpy_s(dir_path, new_buff, var_path);
  wcscat_s(dir_path, new_buff, L"\\directory");

它说缓冲区太小了wcscat_s

4

1 回答 1

1

您只为(并说明该大小)分配new_buff字符,然后您想向其附加更多字符。您需要分配加上的长度,并说明实际大小。dir_pathwcscat_snew_buff L"\\directory"wcscat_s

于 2013-07-22T09:04:48.263 回答