app_server: fix another unchecked out-of-memory case

BString initialization can fail, even when it's allocated on the stack.
Use a const char* to make this code simpler. We lose the ability to
differenciate unknown opcodes, but these should not happen, or the
function should be extended to handle them all.
This commit is contained in:
Adrien Destugues
2019-11-24 13:38:15 +01:00
parent a5483ebd76
commit cc7e3a0522
3 changed files with 8 additions and 16 deletions
+4 -6
View File
@@ -12,14 +12,12 @@
#include <ServerProtocol.h>
void
string_for_message_code(uint32 code, BString& string)
const char*
string_for_message_code(uint32 code)
{
string = "";
switch (code) {
// Return the exact name for each constant
#define CODE(x) case x: string = #x; break
#define CODE(x) case x: return #x
CODE(AS_GET_DESKTOP);
CODE(AS_REGISTER_INPUT_SERVER);
@@ -323,7 +321,7 @@ string_for_message_code(uint32 code, BString& string)
CODE(AS_COLOR_MAP_UPDATED);
default:
string << "unkown code: " << code;
return "unkown code";
break;
}
}
+1 -1
View File
@@ -12,7 +12,7 @@
#include <String.h>
void string_for_message_code(uint32 code, BString& string);
const char* string_for_message_code(uint32 code);
#endif // PROFILE_MESSAGE_SUPPORT_H
+3 -9
View File
@@ -236,13 +236,11 @@ ServerWindow::~ServerWindow()
profiles.SortItems(compare_message_profiles);
BString codeName;
int32 count = profiles.CountItems();
for (int32 i = 0; i < count; i++) {
profile* p = (profile*)profiles.ItemAtFast(i);
string_for_message_code(p->code, codeName);
printf("[%s] called %" B_PRId32 " times, %g secs (%" B_PRId64 " usecs "
"per call)\n", codeName.String(), p->count, p->time / 1000000.0,
"per call)\n", string_for_message_code(p->code), p->count, p->time / 1000000.0,
p->time / p->count);
}
if (sRedrawProcessingTime.count > 0) {
@@ -1184,11 +1182,9 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
default:
if (fCurrentView == NULL) {
BString codeName;
string_for_message_code(code, codeName);
debug_printf("ServerWindow %s received unexpected code - "
"message '%s' before top_view attached.\n",
Title(), codeName.String());
Title(), string_for_message_code(code));
if (link.NeedsReply()) {
fLink.StartMessage(B_ERROR);
fLink.Flush();
@@ -3220,10 +3216,8 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
}
default:
BString codeString;
string_for_message_code(code, codeString);
debug_printf("ServerWindow %s received unexpected code: %s\n",
Title(), codeString.String());
Title(), string_for_message_code(code));
if (link.NeedsReply()) {
// the client is now blocking and waiting for a reply!