Fix static code analyzer warnings

Note: there's more to do ...
This commit is contained in:
Albrecht Schlosser 2020-06-24 20:20:11 +02:00
parent 4c9b44f01e
commit 1da349579d
2 changed files with 27 additions and 19 deletions

View File

@ -296,6 +296,9 @@ static int save_file(const char *filename, const char *code) {
// o 's' will be modified (words will be NULL separated) // o 's' will be modified (words will be NULL separated)
// o argv[] will end up pointing to the words of 's' // o argv[] will end up pointing to the words of 's'
// o Caller must free argv with: free(argv); // o Caller must free argv with: free(argv);
// Returns:
// o -1 in case of memory allocation error
// o number of arguments in argv (same value as in argc)
// //
static int make_args(char *s, // string containing words (gets trashed!) static int make_args(char *s, // string containing words (gets trashed!)
int *aargc, // pointer to argc int *aargc, // pointer to argc
@ -334,11 +337,14 @@ int ExternalCodeEditor::start_editor(const char *editor_cmd,
// NOTE: OSX wants minimal code between fork/exec, see Apple TN2083 // NOTE: OSX wants minimal code between fork/exec, see Apple TN2083
int nargs; int nargs;
char **args = 0; char **args = 0;
make_args(cmd, &nargs, &args); if (make_args(cmd, &nargs, &args) > 0) {
execvp(args[0], args); // run command - doesn't return if succeeds execvp(args[0], args); // run command - doesn't return if succeeds
fl_alert("couldn't exec() '%s': %s", cmd, strerror(errno)); fl_alert("couldn't exec() '%s': %s", cmd, strerror(errno));
exit(1); exit(1);
} }
exit(1);
// break;
}
default: // parent default: // parent
if ( L_editors_open++ == 0 ) // first editor? start timers if ( L_editors_open++ == 0 ) // first editor? start timers
{ start_update_timer(); } { start_update_timer(); }

View File

@ -614,7 +614,10 @@ void Fl_X11_Screen_Driver::open_display_platform() {
XSetErrorHandler(xerror_handler); XSetErrorHandler(xerror_handler);
Display *d = XOpenDisplay(0); Display *d = XOpenDisplay(0);
if (!d) Fl::fatal("Can't open display: %s",XDisplayName(0)); if (!d) {
Fl::fatal("Can't open display: %s", XDisplayName(0)); // does not return
return; // silence static code analyzer
}
open_display_i(d); open_display_i(d);
// the unique GC used by all X windows // the unique GC used by all X windows
@ -956,7 +959,7 @@ void Fl_X11_System_Driver::copy(const char *stuff, int len, int clipboard, const
static void write_short(unsigned char **cp, short i) { static void write_short(unsigned char **cp, short i) {
unsigned char *c = *cp; unsigned char *c = *cp;
*c++ = i & 0xFF; i >>= 8; *c++ = i & 0xFF; i >>= 8;
*c++=i&0xFF;i>>=8; *c++ = i & 0xFF;
*cp = c; *cp = c;
} }
@ -965,7 +968,7 @@ static void write_int(unsigned char **cp,int i){
*c++ = i & 0xFF; i >>= 8; *c++ = i & 0xFF; i >>= 8;
*c++ = i & 0xFF; i >>= 8; *c++ = i & 0xFF; i >>= 8;
*c++ = i & 0xFF; i >>= 8; *c++ = i & 0xFF; i >>= 8;
*c++=i&0xFF;i>>=8; *c++ = i & 0xFF;
*cp = c; *cp = c;
} }
@ -1840,7 +1843,6 @@ int fl_handle(const XEvent& thisevent)
fl_key_vector[keycode/8] |= (1 << (keycode%8)); fl_key_vector[keycode/8] |= (1 << (keycode%8));
static char *kp_buffer = NULL; static char *kp_buffer = NULL;
static int kp_buffer_len = 0; static int kp_buffer_len = 0;
int len=0;
KeySym keysym; KeySym keysym;
if (kp_buffer_len == 0) { if (kp_buffer_len == 0) {
kp_buffer_len = 4096; kp_buffer_len = 4096;
@ -1848,8 +1850,8 @@ int fl_handle(const XEvent& thisevent)
} }
if (xevent.type == KeyPress) { if (xevent.type == KeyPress) {
event = FL_KEYDOWN; event = FL_KEYDOWN;
len = 0;
int len;
if (fl_xim_ic) { if (fl_xim_ic) {
Status status; Status status;
len = XUtf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey, len = XUtf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey,
@ -2017,7 +2019,7 @@ int fl_handle(const XEvent& thisevent)
// Store ASCII numeric keypad value... // Store ASCII numeric keypad value...
keysym = keysym1 | FL_KP; keysym = keysym1 | FL_KP;
kp_buffer[0] = char(keysym1) & 0x7F; kp_buffer[0] = char(keysym1) & 0x7F;
len = 1; // len = 1;
} else { } else {
// Map keypad to special key... // Map keypad to special key...
static const unsigned short table[15] = { static const unsigned short table[15] = {