c++ - wcscat_s function - buffer error -


the question simple: what's frong piece of code?

  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"); 

it says buffer small on wcscat_s

you allocate new_buff characters dir_path (and tell wcscat_s size), want append more characters it. need allocate new_buff plus length of l"\\directory", tell wcscat_s actual size.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -