Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/winpr/libwinpr/path/include/PathCchAppend.h
Line
Count
Source (jump to first uncovered line)
1
2
/*
3
#define DEFINE_UNICODE    FALSE
4
#define CUR_PATH_SEPARATOR_CHR  '\\'
5
#define CUR_PATH_SEPARATOR_STR  "\\"
6
#define PATH_CCH_APPEND   PathCchAppendA
7
*/
8
9
#if DEFINE_UNICODE
10
11
HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
12
0
{
13
0
  BOOL pathBackslash;
14
0
  BOOL moreBackslash;
15
0
  size_t pszMoreLength;
16
0
  size_t pszPathLength;
17
18
0
  if (!pszPath)
19
0
    return E_INVALIDARG;
20
21
0
  if (!pszMore)
22
0
    return E_INVALIDARG;
23
24
0
  if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
25
0
    return E_INVALIDARG;
26
27
0
  pszMoreLength = _wcslen(pszMore);
28
0
  pszPathLength = _wcslen(pszPath);
29
30
0
  pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
31
0
  moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
32
33
0
  if (pathBackslash && moreBackslash)
34
0
  {
35
0
    if ((pszPathLength + pszMoreLength - 1) < cchPath)
36
0
    {
37
0
      WCHAR* ptr = &pszPath[pszPathLength];
38
0
      *ptr = '\0';
39
0
      _wcsncat(ptr, &pszMore[1], _wcslen(&pszMore[1]));
40
0
      return S_OK;
41
0
    }
42
0
  }
43
0
  else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
44
0
  {
45
0
    if ((pszPathLength + pszMoreLength) < cchPath)
46
0
    {
47
0
      WCHAR* ptr = &pszPath[pszPathLength];
48
0
      *ptr = '\0';
49
0
      _wcsncat(ptr, pszMore, _wcslen(pszMore));
50
0
      return S_OK;
51
0
    }
52
0
  }
53
0
  else if (!pathBackslash && !moreBackslash)
54
0
  {
55
0
    if ((pszPathLength + pszMoreLength + 1) < cchPath)
56
0
    {
57
0
      const WCHAR sep[] = CUR_PATH_SEPARATOR_STR;
58
0
      WCHAR* ptr = &pszPath[pszPathLength];
59
0
      *ptr = '\0';
60
0
      _wcsncat(ptr, sep, _wcslen(sep));
61
0
      _wcsncat(ptr, pszMore, _wcslen(pszMore));
62
0
      return S_OK;
63
0
    }
64
0
  }
65
66
0
  return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
67
0
}
Unexecuted instantiation: PathCchAppendW
Unexecuted instantiation: UnixPathCchAppendW
Unexecuted instantiation: NativePathCchAppendW
68
69
#else
70
71
HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
72
0
{
73
0
  BOOL pathBackslash = FALSE;
74
0
  BOOL moreBackslash = FALSE;
75
0
  size_t pszMoreLength;
76
0
  size_t pszPathLength;
77
78
0
  if (!pszPath)
79
0
    return E_INVALIDARG;
80
81
0
  if (!pszMore)
82
0
    return E_INVALIDARG;
83
84
0
  if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
85
0
    return E_INVALIDARG;
86
87
0
  pszPathLength = strlen(pszPath);
88
0
  if (pszPathLength > 0)
89
0
    pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
90
91
0
  pszMoreLength = strlen(pszMore);
92
0
  if (pszMoreLength > 0)
93
0
    moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
94
95
0
  if (pathBackslash && moreBackslash)
96
0
  {
97
0
    if ((pszPathLength + pszMoreLength - 1) < cchPath)
98
0
    {
99
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
100
0
      return S_OK;
101
0
    }
102
0
  }
103
0
  else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
104
0
  {
105
0
    if ((pszPathLength + pszMoreLength) < cchPath)
106
0
    {
107
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
108
0
      return S_OK;
109
0
    }
110
0
  }
111
0
  else if (!pathBackslash && !moreBackslash)
112
0
  {
113
0
    if ((pszPathLength + pszMoreLength + 1) < cchPath)
114
0
    {
115
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s",
116
0
                pszMore);
117
0
      return S_OK;
118
0
    }
119
0
  }
120
121
0
  return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
122
0
}
Unexecuted instantiation: PathCchAppendA
Unexecuted instantiation: UnixPathCchAppendA
Unexecuted instantiation: NativePathCchAppendA
123
124
#endif
125
126
/*
127
#undef DEFINE_UNICODE
128
#undef CUR_PATH_SEPARATOR_CHR
129
#undef CUR_PATH_SEPARATOR_STR
130
#undef PATH_CCH_APPEND
131
*/