mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 02:46:34 +08:00
Fix test/editor use of strncy to strlcpy
This commit is contained in:
@@ -52,6 +52,7 @@ marked in the source code as `TUTORIAL_CHAPTER = 1`.
|
|||||||
\code
|
\code
|
||||||
#include <FL/Fl_Double_Window.H>
|
#include <FL/Fl_Double_Window.H>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
Fl_Double_Window *app_window = NULL;
|
Fl_Double_Window *app_window = NULL;
|
||||||
|
|
||||||
@@ -365,7 +366,7 @@ little chunk of code will separate the file name from the path before we call
|
|||||||
// insert before `if (file_chooser.show()...`
|
// insert before `if (file_chooser.show()...`
|
||||||
if (app_filename[0]) {
|
if (app_filename[0]) {
|
||||||
char temp_filename[FL_PATH_MAX];
|
char temp_filename[FL_PATH_MAX];
|
||||||
strncpy(temp_filename, app_filename, FL_PATH_MAX-1);
|
strlcpy(temp_filename, app_filename, FL_PATH_MAX);
|
||||||
const char *name = fl_filename_name(temp_filename);
|
const char *name = fl_filename_name(temp_filename);
|
||||||
if (name) {
|
if (name) {
|
||||||
file_chooser.preset_file(name);
|
file_chooser.preset_file(name);
|
||||||
@@ -478,7 +479,7 @@ name:
|
|||||||
...
|
...
|
||||||
if (app_filename[0]) {
|
if (app_filename[0]) {
|
||||||
char temp_filename[FL_PATH_MAX];
|
char temp_filename[FL_PATH_MAX];
|
||||||
strncpy(temp_filename, app_filename, FL_PATH_MAX-1);
|
strlcpy(temp_filename, app_filename, FL_PATH_MAX);
|
||||||
const char *name = fl_filename_name(temp_filename);
|
const char *name = fl_filename_name(temp_filename);
|
||||||
if (name) {
|
if (name) {
|
||||||
file_chooser.preset_file(name);
|
file_chooser.preset_file(name);
|
||||||
@@ -647,7 +648,7 @@ char last_find_text[1024] = "";
|
|||||||
void menu_find_callback(Fl_Widget*, void* v) {
|
void menu_find_callback(Fl_Widget*, void* v) {
|
||||||
const char *find_text = fl_input("Find in text:", last_find_text);
|
const char *find_text = fl_input("Find in text:", last_find_text);
|
||||||
if (find_text) {
|
if (find_text) {
|
||||||
strncpy(last_find_text, find_text, sizeof(last_find_text)-1);
|
strlcpy(last_find_text, find_text, sizeof(last_find_text));
|
||||||
find_next(find_text);
|
find_next(find_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -811,8 +812,8 @@ function:
|
|||||||
\code
|
\code
|
||||||
void Replace_Dialog::find_next_callback(Fl_Widget*, void* my_dialog) {
|
void Replace_Dialog::find_next_callback(Fl_Widget*, void* my_dialog) {
|
||||||
Replace_Dialog *dlg = static_cast<Replace_Dialog*>(my_dialog);
|
Replace_Dialog *dlg = static_cast<Replace_Dialog*>(my_dialog);
|
||||||
strncpy(last_find_text, dlg->find_text_input->value(), sizeof(last_find_text)-1);
|
strlcpy(last_find_text, dlg->find_text_input->value(), sizeof(last_find_text));
|
||||||
strncpy(last_replace_text, dlg->replace_text_input->value(), sizeof(last_replace_text)-1);
|
strlcpy(last_replace_text, dlg->replace_text_input->value(), sizeof(last_replace_text));
|
||||||
if (last_find_text[0])
|
if (last_find_text[0])
|
||||||
find_next(last_find_text);
|
find_next(last_find_text);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <FL/Fl_Double_Window.H>
|
#include <FL/Fl_Double_Window.H>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
Fl_Double_Window *app_window = NULL;
|
Fl_Double_Window *app_window = NULL;
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ void set_changed(bool v) {
|
|||||||
|
|
||||||
void set_filename(const char *new_filename) {
|
void set_filename(const char *new_filename) {
|
||||||
if (new_filename) {
|
if (new_filename) {
|
||||||
strncpy(app_filename, new_filename, FL_PATH_MAX);
|
strlcpy(app_filename, new_filename, FL_PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
app_filename[0] = 0;
|
app_filename[0] = 0;
|
||||||
}
|
}
|
||||||
@@ -187,7 +188,7 @@ void menu_save_as_callback(Fl_Widget*, void*) {
|
|||||||
file_chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
file_chooser.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||||
if (app_filename[0]) {
|
if (app_filename[0]) {
|
||||||
char temp_filename[FL_PATH_MAX];
|
char temp_filename[FL_PATH_MAX];
|
||||||
strncpy(temp_filename, app_filename, FL_PATH_MAX-1);
|
strlcpy(temp_filename, app_filename, FL_PATH_MAX);
|
||||||
const char *name = fl_filename_name(temp_filename);
|
const char *name = fl_filename_name(temp_filename);
|
||||||
if (name) {
|
if (name) {
|
||||||
file_chooser.preset_file(name);
|
file_chooser.preset_file(name);
|
||||||
@@ -262,7 +263,7 @@ void menu_open_callback(Fl_Widget*, void*) {
|
|||||||
file_chooser.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
file_chooser.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
||||||
if (app_filename[0]) {
|
if (app_filename[0]) {
|
||||||
char temp_filename[FL_PATH_MAX];
|
char temp_filename[FL_PATH_MAX];
|
||||||
strncpy(temp_filename, app_filename, FL_PATH_MAX-1);
|
strlcpy(temp_filename, app_filename, FL_PATH_MAX);
|
||||||
const char *name = fl_filename_name(temp_filename);
|
const char *name = fl_filename_name(temp_filename);
|
||||||
if (name) {
|
if (name) {
|
||||||
file_chooser.preset_file(name);
|
file_chooser.preset_file(name);
|
||||||
@@ -398,7 +399,7 @@ bool find_next(const char *needle) {
|
|||||||
void menu_find_callback(Fl_Widget*, void* v) {
|
void menu_find_callback(Fl_Widget*, void* v) {
|
||||||
const char *find_text = fl_input("Find in text:", last_find_text);
|
const char *find_text = fl_input("Find in text:", last_find_text);
|
||||||
if (find_text) {
|
if (find_text) {
|
||||||
strncpy(last_find_text, find_text, sizeof(last_find_text)-1);
|
strlcpy(last_find_text, find_text, sizeof(last_find_text));
|
||||||
find_next(find_text);
|
find_next(find_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,8 +497,8 @@ void Replace_Dialog::show() {
|
|||||||
|
|
||||||
void Replace_Dialog::find_next_callback(Fl_Widget*, void* my_dialog) {
|
void Replace_Dialog::find_next_callback(Fl_Widget*, void* my_dialog) {
|
||||||
Replace_Dialog *dlg = static_cast<Replace_Dialog*>(my_dialog);
|
Replace_Dialog *dlg = static_cast<Replace_Dialog*>(my_dialog);
|
||||||
strncpy(last_find_text, dlg->find_text_input->value(), sizeof(last_find_text)-1);
|
strlcpy(last_find_text, dlg->find_text_input->value(), sizeof(last_find_text));
|
||||||
strncpy(last_replace_text, dlg->replace_text_input->value(), sizeof(last_replace_text)-1);
|
strlcpy(last_replace_text, dlg->replace_text_input->value(), sizeof(last_replace_text));
|
||||||
if (last_find_text[0])
|
if (last_find_text[0])
|
||||||
find_next(last_find_text);
|
find_next(last_find_text);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user