Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/winpr/libwinpr/path/include/PathCchAddExtension.h
Line
Count
Source (jump to first uncovered line)
1
2
/*
3
#define DEFINE_UNICODE    FALSE
4
#define CUR_PATH_SEPARATOR_CHR  '\\'
5
#define PATH_CCH_ADD_EXTENSION  PathCchAddExtensionA
6
*/
7
8
#if DEFINE_UNICODE
9
10
HRESULT PATH_CCH_ADD_EXTENSION(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
11
0
{
12
0
  LPWSTR pDot;
13
0
  BOOL bExtDot;
14
0
  LPWSTR pBackslash;
15
0
  size_t pszExtLength;
16
0
  size_t pszPathLength;
17
18
0
  if (!pszPath)
19
0
    return E_INVALIDARG;
20
21
0
  if (!pszExt)
22
0
    return E_INVALIDARG;
23
24
0
  pszExtLength = _wcslen(pszExt);
25
0
  pszPathLength = _wcslen(pszPath);
26
0
  bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
27
28
0
  pDot = _wcsrchr(pszPath, '.');
29
0
  pBackslash = _wcsrchr(pszPath, CUR_PATH_SEPARATOR_CHR);
30
31
0
  if (pDot && pBackslash)
32
0
  {
33
0
    if (pDot > pBackslash)
34
0
      return S_FALSE;
35
0
  }
36
37
0
  if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
38
0
  {
39
0
    const WCHAR dot[] = { '.', '\0' };
40
0
    WCHAR* ptr = &pszPath[pszPathLength];
41
0
    *ptr = '\0';
42
43
0
    if (!bExtDot)
44
0
      _wcsncat(ptr, dot, _wcslen(dot));
45
0
    _wcsncat(ptr, pszExt, pszExtLength);
46
47
0
    return S_OK;
48
0
  }
49
50
0
  return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
51
0
}
Unexecuted instantiation: PathCchAddExtensionW
Unexecuted instantiation: UnixPathCchAddExtensionW
Unexecuted instantiation: NativePathCchAddExtensionW
52
53
#else
54
55
HRESULT PATH_CCH_ADD_EXTENSION(PSTR pszPath, size_t cchPath, PCSTR pszExt)
56
0
{
57
0
  CHAR* pDot;
58
0
  BOOL bExtDot;
59
0
  CHAR* pBackslash;
60
0
  size_t pszExtLength;
61
0
  size_t pszPathLength;
62
63
0
  if (!pszPath)
64
0
    return E_INVALIDARG;
65
66
0
  if (!pszExt)
67
0
    return E_INVALIDARG;
68
69
0
  pszExtLength = strlen(pszExt);
70
0
  pszPathLength = strlen(pszPath);
71
0
  bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
72
73
0
  pDot = strrchr(pszPath, '.');
74
0
  pBackslash = strrchr(pszPath, CUR_PATH_SEPARATOR_CHR);
75
76
0
  if (pDot && pBackslash)
77
0
  {
78
0
    if (pDot > pBackslash)
79
0
      return S_FALSE;
80
0
  }
81
82
0
  if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
83
0
  {
84
0
    if (bExtDot)
85
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszExt);
86
0
    else
87
0
      sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, ".%s", pszExt);
88
89
0
    return S_OK;
90
0
  }
91
92
0
  return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
93
0
}
Unexecuted instantiation: PathCchAddExtensionA
Unexecuted instantiation: UnixPathCchAddExtensionA
Unexecuted instantiation: NativePathCchAddExtensionA
94
95
#endif
96
97
/*
98
#undef DEFINE_UNICODE
99
#undef CUR_PATH_SEPARATOR_CHR
100
#undef PATH_CCH_ADD_EXTENSION
101
*/