Skip to content

Commit c7915c6

Browse files
committed
Fix a bug when constructing a std::string from a ROString
1 parent 01ff48d commit c7915c6

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

example/lottieviewtest.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ class LottieViewTest
5353
ecore_animator_frametime_set(1.0f/120.0f);
5454
}
5555

56+
void show(const char * filepath) {
57+
std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mStrategy));
58+
view->setFilePath(filepath);
59+
view->setPos(3, 3);
60+
int vw = mApp->width() - 6;
61+
view->setSize(vw, vw);
62+
view->show();
63+
view->play();
64+
view->loop(true);
65+
mViews.push_back(std::move(view));
66+
}
67+
68+
5669
void show(int numberOfImage) {
5770
auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
5871

@@ -92,9 +105,10 @@ class LottieViewTest
92105
}
93106

94107
static int help() {
95-
printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count]\n");
108+
printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count] [-f] path\n");
96109
printf("\n \t-t : timeout duration in seconds\n");
97110
printf("\n \t-c : number of resource in the grid\n");
111+
printf("\n \t-f : File to play\n");
98112
printf("\n \t-s : Rendering Strategy\n");
99113
printf("\t\t 0 - Test Lottie SYNC Renderer with CPP API\n");
100114
printf("\t\t 1 - Test Lottie ASYNC Renderer with CPP API\n");
@@ -134,6 +148,7 @@ main(int argc, char **argv)
134148
auto index = 0;
135149
double timeOut = 0;
136150
size_t itemCount = 250;
151+
std::string filePath;
137152
while (index < argc) {
138153
const char* option = argv[index];
139154
index++;
@@ -148,14 +163,18 @@ main(int argc, char **argv)
148163
} else if (!strcmp(option,"-c")) {
149164
itemCount = (index < argc) ? atoi(argv[index]) : 10;
150165
index++;
166+
} else if (!strcmp(option,"-f")) {
167+
filePath = argv[index];
168+
index++;
151169
}
152170
}
153171

154172
EvasApp *app = new EvasApp(800, 800);
155173
app->setup();
156174

157175
LottieViewTest *view = new LottieViewTest(app, st, timeOut);
158-
view->show(itemCount);
176+
if (filePath.length()) view->show(filePath.c_str());
177+
else view->show(itemCount);
159178

160179
app->addExitCb(onExitCb, view);
161180

inc/rlottiecommon.h

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
#endif
3838
#endif
3939

40+
#if defined LOTTIE_JSON_SUPPORT
41+
#define RLOTTIE_FEATURE_RO_JSON 1
42+
#else
43+
#define RLOTTIE_FEATURE_RO_JSON 0
44+
#endif
45+
46+
#if defined LOTTIE_THREAD_SUPPORT
47+
#define RLOTTIE_FEATURE_THREAD 1
48+
#else
49+
#define RLOTTIE_FEATURE_THREAD 0
50+
#endif
51+
52+
#if defined LOTTIE_NO_PARTIAL_RENDER
53+
#define RLOTTIE_FEATURE_PARTIAL_RENDER 0
54+
#else
55+
#define RLOTTIE_FEATURE_PARTIAL_RENDER 1
56+
#endif
57+
4058

4159
/**
4260
* @defgroup Lottie_Animation Lottie_Animation

src/lottie/JSON

src/lottie/lottiemodel.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,15 @@ class Object {
475475
if (name) {
476476
if (len < maxShortStringLength) {
477477
setShortString(true);
478-
strncpy(mData._buffer, name, len + 1);
478+
memcpy(mData._buffer, name, len);
479+
mData._buffer[len] = 0;
479480
} else {
480481
setShortString(false);
481-
mPtr = strdup(name);
482+
mPtr = (char*)malloc(len+1);
483+
if (mPtr) {
484+
memcpy(mPtr, name, len);
485+
mPtr[len] = 0;
486+
}
482487
}
483488
}
484489
}

src/lottie/lottieroparser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ std::string LottieParserImpl::GetStringObject()
490490
ROString str = GetString();
491491

492492
if (str) {
493-
return std::string(str, str.getLength());
493+
return std::string(str.getData(), str.getLength());
494494
}
495495

496496
return {};

src/lottie/meson.build

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
source_file = [
3-
'lottieparser.cpp',
43
'lottieloader.cpp',
54
'lottiemodel.cpp',
65
'lottieproxymodel.cpp',
@@ -10,6 +9,13 @@ source_file = [
109
'lottiekeypath.cpp'
1110
]
1211

12+
if get_option('json')
13+
source_file += ['lottieroparser.cpp']
14+
else
15+
source_file += ['lottieparser.cpp']
16+
endif
17+
18+
1319
lottie_dep = declare_dependency(
1420
include_directories : include_directories('.'),
1521
sources : source_file

0 commit comments

Comments
 (0)