mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 17:58:31 +02:00
Merge branch 'fix-Wstringop-overflow'
This commit is contained in:
commit
764f657620
@ -726,15 +726,15 @@ bool cNumericExpr::IsNumericExpression(const char *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cNumericExpr::PercentValue(const char *e) {
|
bool cNumericExpr::PercentValue(const char *e) {
|
||||||
|
if (!e)
|
||||||
|
return e;
|
||||||
const char *hit = strchr(e, '%');
|
const char *hit = strchr(e, '%');
|
||||||
if (!hit)
|
if (!hit)
|
||||||
return false;
|
return false;
|
||||||
char buffer[20] = "";
|
int val;
|
||||||
if (strlen(e) > 20)
|
int r = sscanf(e, "%d%%", &val); // use sscanf to retrieve %-value to avoid -Wstringop-overflow
|
||||||
return false;
|
if (r != 1)
|
||||||
strncpy(buffer, e, strlen(e)-1);
|
return false; // sscanf parsing problem
|
||||||
buffer[strlen(e)-1] = '\0';
|
|
||||||
int val = atoi(buffer);
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (horizontal && container->Width() > 0) {
|
if (horizontal && container->Width() > 0) {
|
||||||
value = container->Width() * val / 100;
|
value = container->Width() * val / 100;
|
||||||
@ -747,22 +747,22 @@ bool cNumericExpr::PercentValue(const char *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *cNumericExpr::ReplacePercentValue(char *e) {
|
char *cNumericExpr::ReplacePercentValue(char *e) {
|
||||||
|
if (!e)
|
||||||
|
return e;
|
||||||
const char *hit = strchr(e, '%');
|
const char *hit = strchr(e, '%');
|
||||||
if (!hit)
|
if (!hit)
|
||||||
return e;
|
return e;
|
||||||
char buffer[20] = "";
|
int val;
|
||||||
if (strlen(e) > 20)
|
int r = sscanf(e, "%d%%", &val); // use sscanf to retrieve %-value to avoid -Wstringop-overflow
|
||||||
return e;
|
if (r != 1)
|
||||||
strncpy(buffer, e, strlen(e)-1);
|
return e; // sscanf parsing problem
|
||||||
buffer[strlen(e)-1] = '\0';
|
|
||||||
int val = atoi(buffer);
|
|
||||||
double percentVal = (double)val/100.0f;
|
double percentVal = (double)val/100.0f;
|
||||||
|
|
||||||
char replacement[50] = "";
|
char replacement[50] = "";
|
||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
sprintf(replacement, "%.5f*{areawidth}", percentVal);
|
snprintf(replacement, sizeof(replacement), "%.5f*{areawidth}", percentVal);
|
||||||
} else {
|
} else {
|
||||||
sprintf(replacement, "%.5f*{areaheight}", percentVal);
|
snprintf(replacement, sizeof(replacement), "%.5f*{areaheight}", percentVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = strlen(replacement) + 1;
|
int len = strlen(replacement) + 1;
|
||||||
@ -774,16 +774,19 @@ char *cNumericExpr::ReplacePercentValue(char *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *cNumericExpr::ReplaceToken(char *e, const char* token, int val) {
|
char *cNumericExpr::ReplaceToken(char *e, const char* token, int val) {
|
||||||
|
if (!e)
|
||||||
|
return e;
|
||||||
char *tokenStart = strstr(e, token);
|
char *tokenStart = strstr(e, token);
|
||||||
if (!tokenStart) {
|
if (!tokenStart) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
char buffer[20] = "";
|
char buffer[20] = "";
|
||||||
sprintf(buffer, "%d", val);
|
snprintf(buffer, sizeof(buffer), "%d", val);
|
||||||
size_t newSize = strlen(e) - strlen(token) + strlen(buffer) + 1;
|
size_t newSize = strlen(e) - strlen(token) + strlen(buffer) + 1;
|
||||||
char *replaced = (char*)malloc(newSize);
|
char *replaced = (char*)malloc(newSize);
|
||||||
memset(replaced, 0, newSize);
|
memset(replaced, 0, newSize);
|
||||||
size_t beginning = strlen(e) - strlen(tokenStart);
|
size_t beginning = strlen(e) - strlen(tokenStart);
|
||||||
|
if (beginning >= newSize) beginning = newSize - 1; // will never happen but avoid -Wstringop-overflow
|
||||||
if (beginning > 0)
|
if (beginning > 0)
|
||||||
strncpy(replaced, e, beginning);
|
strncpy(replaced, e, beginning);
|
||||||
strcat(replaced, buffer);
|
strcat(replaced, buffer);
|
||||||
|
@ -178,14 +178,14 @@ cImageImporterSVG::cImageImporterSVG() {
|
|||||||
|
|
||||||
cImageImporterSVG::~cImageImporterSVG() {
|
cImageImporterSVG::~cImageImporterSVG() {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
rsvg_handle_close(handle, NULL); // deprecated since version 2.46
|
rsvg_handle_close(handle, NULL); // TODO: deprecated since version 2.46
|
||||||
g_object_unref(handle);
|
g_object_unref(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cImageImporterSVG::LoadImage(const char *path) {
|
bool cImageImporterSVG::LoadImage(const char *path) {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
rsvg_handle_close(handle, NULL); // deprecated since version 2.46
|
rsvg_handle_close(handle, NULL); // TODO: deprecated since version 2.46
|
||||||
g_object_unref(handle);
|
g_object_unref(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user