[ion/events] Fix ExternalText buffer size

The size of the ExternalText events shared buffer is now defined as the
size of the SDL_TextInputEvent 'text' field, as it should.
Also fix a wrong parameter being passed to a strlcpy.

Change-Id: I6a57d49d61fec8a009c4711efce564c65544e571
This commit is contained in:
Gabriel Ozouf
2020-10-22 12:29:47 +02:00
committed by Émilie Feral
parent b0b6fe33c9
commit aadf8f5716
3 changed files with 4 additions and 3 deletions

View File

@@ -1,7 +1,6 @@
#include "events.h"
#include "haptics.h"
#include <ion/events.h>
#include <SDL.h>
namespace Ion {
namespace Events {
@@ -11,7 +10,7 @@ void didPressNewKey() {
}
char * sharedExternalTextBuffer() {
static char buffer[32];
static char buffer[sharedExternalTextBufferSize];
return buffer;
}

View File

@@ -2,6 +2,7 @@
#define ION_SIMULATOR_EVENTS_H
#include <ion/events.h>
#include <SDL.h>
namespace Ion {
namespace Simulator {
@@ -15,6 +16,7 @@ void logAfter(int numberOfEvents);
namespace Events {
static constexpr size_t sharedExternalTextBufferSize = sizeof(SDL_TextInputEvent::text);
char * sharedExternalTextBuffer();
constexpr Event ExternalText = Event::Special(6);

View File

@@ -170,7 +170,7 @@ static Event eventFromSDLTextInputEvent(SDL_TextInputEvent event) {
return None;
}
Ion::Events::removeShift();
strlcpy(sharedExternalTextBuffer(), event.text, strlen(event.text) + 1);
strlcpy(sharedExternalTextBuffer(), event.text, sharedExternalTextBufferSize);
return ExternalText;
}