Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2358?usp=email
to review the following change.
Change subject: openvpnmsica: Clean up sign conversion warnings
......................................................................
openvpnmsica: Clean up sign conversion warnings
Improve code in x_msg_va to handle vsnprintf result.
Removes explict null termination that is not required
in supported versions of Windows.
Includes one unrelated cast that is too small to
warrant its own commit.
Change-Id: Ia5c265bd1f2723be93fb8fbb73e73a4e86d1cac7
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpnmsica/dllmain.c
1 file changed, 19 insertions(+), 25 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/2358/1
diff --git a/src/openvpnmsica/dllmain.c b/src/openvpnmsica/dllmain.c
index 777c823..e191207 100644
--- a/src/openvpnmsica/dllmain.c
+++ b/src/openvpnmsica/dllmain.c
@@ -98,11 +98,6 @@
return true;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
void
x_msg_va(const unsigned int flags, const char *format, va_list arglist)
{
@@ -124,26 +119,29 @@
/* Field 2: The message string. */
char szBufStack[128];
int iResultLen = vsnprintf(szBufStack, _countof(szBufStack), format,
arglist);
- if (iResultLen > 0 && (unsigned int)iResultLen < _countof(szBufStack))
+ if (iResultLen > 0)
{
- /* Use from stack. */
- MsiRecordSetStringA(hRecordProg, 2, szBufStack);
- }
- else
- {
- /* Allocate on heap and retry. */
- char *szMessage = (char *)malloc(++iResultLen * sizeof(char));
- if (szMessage != NULL)
+ const size_t alloc_size = (size_t)iResultLen + 1;
+ if (alloc_size <= _countof(szBufStack))
{
- vsnprintf(szMessage, iResultLen, format, arglist);
- MsiRecordSetStringA(hRecordProg, 2, szMessage);
- free(szMessage);
+ /* Use from stack. */
+ MsiRecordSetStringA(hRecordProg, 2, szBufStack);
}
else
{
- /* Use stack variant anyway, but make sure it's
zero-terminated. */
- szBufStack[_countof(szBufStack) - 1] = 0;
- MsiRecordSetStringA(hRecordProg, 2, szBufStack);
+ /* Allocate on heap and retry. */
+ char *szMessage = malloc(alloc_size);
+ if (szMessage != NULL)
+ {
+ vsnprintf(szMessage, alloc_size, format, arglist);
+ MsiRecordSetStringA(hRecordProg, 2, szMessage);
+ free(szMessage);
+ }
+ else
+ {
+ /* Use truncated stack variant anyway */
+ MsiRecordSetStringA(hRecordProg, 2, szBufStack);
+ }
}
}
}
@@ -159,7 +157,7 @@
MsiRecordSetInteger(hRecordProg, 1, ERROR_MSICA_ERRNO);
/* Field 3: The Windows error number. */
- MsiRecordSetInteger(hRecordProg, 3, dwResult);
+ MsiRecordSetInteger(hRecordProg, 3, (int)dwResult);
/* Field 4: The Windows error description. */
LPWSTR szErrMessage = NULL;
@@ -194,7 +192,3 @@
hRecordProg);
MsiCloseHandle(hRecordProg);
}
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2358?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia5c265bd1f2723be93fb8fbb73e73a4e86d1cac7
Gerrit-Change-Number: 2358
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel