mirror of
https://github.com/fltk/fltk.git
synced 2026-06-05 16:12:13 +08:00
FLUID writes RGB and Bitmap image data as an array of decimal numbers instead of a string since "a certain compiler by a large operating system vendor which shall remain unnamed" can not handle long strings and produces heap overflows.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4607 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -732,6 +732,7 @@ void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
|
|||||||
void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
|
void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
|
||||||
void write_cstring(const char *);
|
void write_cstring(const char *);
|
||||||
void write_cstring(const char *,int length);
|
void write_cstring(const char *,int length);
|
||||||
|
void write_cdata(const char *,int length);
|
||||||
void write_indent(int n);
|
void write_indent(int n);
|
||||||
void write_open(int);
|
void write_open(int);
|
||||||
void write_close(int n);
|
void write_close(int n);
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void Fluid_Image::write_static() {
|
|||||||
}
|
}
|
||||||
write_c("static unsigned char %s[] =\n",
|
write_c("static unsigned char %s[] =\n",
|
||||||
unique_id(this, "idata", fl_filename_name(name()), 0));
|
unique_id(this, "idata", fl_filename_name(name()), 0));
|
||||||
write_cstring(img->data()[0], ((img->w() + 7) / 8) * img->h());
|
write_cdata(img->data()[0], ((img->w() + 7) / 8) * img->h());
|
||||||
write_c(";\n");
|
write_c(";\n");
|
||||||
write_c("static Fl_Bitmap %s(%s, %d, %d);\n",
|
write_c("static Fl_Bitmap %s(%s, %d, %d);\n",
|
||||||
unique_id(this, "image", fl_filename_name(name()), 0),
|
unique_id(this, "image", fl_filename_name(name()), 0),
|
||||||
@@ -109,7 +109,7 @@ void Fluid_Image::write_static() {
|
|||||||
}
|
}
|
||||||
write_c("static unsigned char %s[] =\n",
|
write_c("static unsigned char %s[] =\n",
|
||||||
unique_id(this, "idata", fl_filename_name(name()), 0));
|
unique_id(this, "idata", fl_filename_name(name()), 0));
|
||||||
write_cstring(img->data()[0], (img->w() * img->d() + img->ld()) * img->h());
|
write_cdata(img->data()[0], (img->w() * img->d() + img->ld()) * img->h());
|
||||||
write_c(";\n");
|
write_c(";\n");
|
||||||
write_c("static Fl_RGB_Image %s(%s, %d, %d, %d, %d);\n",
|
write_c("static Fl_RGB_Image %s(%s, %d, %d, %d, %d);\n",
|
||||||
unique_id(this, "image", fl_filename_name(name()), 0),
|
unique_id(this, "image", fl_filename_name(name()), 0),
|
||||||
|
|||||||
@@ -226,6 +226,25 @@ void write_cstring(const char *w, int length) {
|
|||||||
// write a C string, quoting characters if necessary:
|
// write a C string, quoting characters if necessary:
|
||||||
void write_cstring(const char *w) {write_cstring(w,strlen(w));}
|
void write_cstring(const char *w) {write_cstring(w,strlen(w));}
|
||||||
|
|
||||||
|
// write an array of C binary data (does not add a null):
|
||||||
|
void write_cdata(const char *s, int length) {
|
||||||
|
if (varused_test) return;
|
||||||
|
const unsigned char *w = (const unsigned char *)s;
|
||||||
|
const unsigned char *e = w+length;
|
||||||
|
int linelength = 1;
|
||||||
|
putc('{', code_file);
|
||||||
|
for (; w < e;) {
|
||||||
|
unsigned char c = *w++;
|
||||||
|
if (c>99) linelength += 4;
|
||||||
|
else if (c>9) linelength += 3;
|
||||||
|
else linelength += 2;
|
||||||
|
if (linelength >= 77) {fputs("\n",code_file); linelength = 0;}
|
||||||
|
fprintf(code_file, "%d", c);
|
||||||
|
if (w<e) putc(',', code_file);
|
||||||
|
}
|
||||||
|
putc('}', code_file);
|
||||||
|
}
|
||||||
|
|
||||||
void write_c(const char* format,...) {
|
void write_c(const char* format,...) {
|
||||||
if (varused_test) {varused = 1; return;}
|
if (varused_test) {varused = 1; return;}
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|||||||
+17
-8
@@ -26,20 +26,29 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Double_Window.H>
|
||||||
#include <FL/Fl_Box.H>
|
#include <FL/Fl_Button.H>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void WinQuit_CB(Fl_Widget*, void*) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
Fl_Window *window = new Fl_Window(300,180);
|
Fl_Double_Window *window;
|
||||||
Fl_Box *box = new Fl_Box(FL_UP_BOX,20,40,260,100,"Hello, World!");
|
{ Fl_Double_Window *o = new Fl_Double_Window(347, 263);
|
||||||
box->labelfont(FL_BOLD+FL_ITALIC);
|
window = o;
|
||||||
box->labelsize(36);
|
{ Fl_Button *o = new Fl_Button(25, 25, 64, 20, "button");
|
||||||
box->labeltype(FL_SHADOW_LABEL);
|
o->callback(WinQuit_CB);
|
||||||
window->end();
|
}
|
||||||
|
o->end();
|
||||||
|
}
|
||||||
window->show(argc, argv);
|
window->show(argc, argv);
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id$".
|
// End of "$Id$".
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user