Fix according to review

This commit is contained in:
Kartik 2017-03-02 12:59:42 +05:30 committed by GitHub
parent b1592a3539
commit 51ac5111c5

View File

@ -1,14 +1,10 @@
#include <3ds.h> #include <3ds.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include <3ds/types.h> #include <3ds/types.h>
#include <3ds/result.h>
#include <3ds/svc.h> #include <3ds/svc.h>
#include <3ds/synchronization.h> #include <3ds/synchronization.h>
#include <3ds/services/apt.h> #include <3ds/services/apt.h>
#include <3ds/ipc.h>
#include <3ds/env.h>
#include <3ds/util/utf.h> #include <3ds/util/utf.h>
#include <3ds/applets/error.h> #include <3ds/applets/error.h>
@ -25,7 +21,7 @@ void error_Init(ErrConf* err, ErrorType type, err_lang lang)
err-> returnCode = UNKNOWN; err-> returnCode = UNKNOWN;
} }
static void errorConvertToUTF16(u16* out, const char* in, int max) static void errorConvertToUTF16(u16* out, const char* in, size_t max)
{ {
if (!in || !*in) if (!in || !*in)
{ {
@ -33,7 +29,7 @@ static void errorConvertToUTF16(u16* out, const char* in, int max)
return; return;
} }
ssize_t units = utf8_to_utf16(out, (const uint8_t*)in, max); ssize_t units = utf8_to_utf16(out, (const uint8_t*)in, max-1);
if (units < 0) if (units < 0)
{ {
out[0] = 0; out[0] = 0;
@ -42,30 +38,28 @@ static void errorConvertToUTF16(u16* out, const char* in, int max)
out[units] = 0; out[units] = 0;
} }
char k[1900];
char *c_shift(char text[]) static char* c_shift(const char *text)
{ {
int i=strlen(text); size_t len = strlen(text);
char tex[i]; char *str = (char*)malloc(len + 2);
tex[0]=text[0]; if(str)
int j=1;
for(int a=0;a<=i;a++)
{ {
tex[j]=text[a]; str[0] = text[0];
j++; strcpy(&str[1], text);
} }
strncpy(k, tex, i+1); return str;
return k;
} }
void error_code(ErrConf* err,int error) void error_code(ErrConf* err,int error)
{ {
err->errorCode = error; err->errorCode = error;
} }
void error_text(ErrConf *err, char* text) void error_text(ErrConf *err, char* text)
{ { char *tex=c_shift(text);
char *tex=c_shift(text);
errorConvertToUTF16(err->Text, tex, 1900); errorConvertToUTF16(err->Text, tex, 1900);
free(tex);
} }
void error_disp(ErrConf* err) void error_disp(ErrConf* err)