mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-03 15:34:54 -05:00
Add comment to avoid mistake later, remove alloca
* Add comments so previous mistake is not repeated. * Remove alloca, replace it by strdup/asprintf. Code now passes cppcheck.
This commit is contained in:
parent
a0a5400c72
commit
832c2cb584
2 changed files with 15 additions and 3 deletions
|
@ -114,6 +114,7 @@ static pid_t exec_cmd ( const char *cmd, int run_in_term )
|
||||||
}
|
}
|
||||||
retv = reallocate ( retv, ( index + 2 ) * sizeof ( element* ) );
|
retv = reallocate ( retv, ( index + 2 ) * sizeof ( element* ) );
|
||||||
retv[index] = allocate ( sizeof ( element ) );
|
retv[index] = allocate ( sizeof ( element ) );
|
||||||
|
// remove trailing \n
|
||||||
buffer[strlen ( buffer ) - 1] = '\0';
|
buffer[strlen ( buffer ) - 1] = '\0';
|
||||||
char * start = NULL;
|
char * start = NULL;
|
||||||
retv[index]->index = strtol ( buffer, &start, 10 );
|
retv[index]->index = strtol ( buffer, &start, 10 );
|
||||||
|
@ -208,6 +209,7 @@ static void delete_entry ( const char *cmd )
|
||||||
}
|
}
|
||||||
retv = reallocate ( retv, ( index + 2 ) * sizeof ( element* ) );
|
retv = reallocate ( retv, ( index + 2 ) * sizeof ( element* ) );
|
||||||
retv[index] = allocate ( sizeof ( element ) );
|
retv[index] = allocate ( sizeof ( element ) );
|
||||||
|
// remove trailing \n
|
||||||
buffer[strlen ( buffer ) - 1] = '\0';
|
buffer[strlen ( buffer ) - 1] = '\0';
|
||||||
retv[index]->index = strtol ( buffer, &start, 10 );
|
retv[index]->index = strtol ( buffer, &start, 10 );
|
||||||
snprintf ( retv[index]->name, RUN_DIALOG_NAME_LENGTH, "%s", start + 1 );
|
snprintf ( retv[index]->name, RUN_DIALOG_NAME_LENGTH, "%s", start + 1 );
|
||||||
|
@ -291,6 +293,7 @@ static char ** get_apps ( )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// remove trailing \n
|
||||||
buffer[strlen ( buffer ) - 1] = '\0';
|
buffer[strlen ( buffer ) - 1] = '\0';
|
||||||
char *start = NULL;
|
char *start = NULL;
|
||||||
// Don't use result.
|
// Don't use result.
|
||||||
|
|
|
@ -210,7 +210,7 @@ void textbox_draw ( textbox *tb )
|
||||||
// clear canvas
|
// clear canvas
|
||||||
XftDrawRect ( draw, &tb->color_bg, 0, 0, tb->w, tb->h );
|
XftDrawRect ( draw, &tb->color_bg, 0, 0, tb->w, tb->h );
|
||||||
|
|
||||||
char *line = tb->text,
|
char *line = NULL,
|
||||||
*text = tb->text ? tb->text : "",
|
*text = tb->text ? tb->text : "",
|
||||||
*prompt = tb->prompt ? tb->prompt : "";
|
*prompt = tb->prompt ? tb->prompt : "";
|
||||||
|
|
||||||
|
@ -229,8 +229,11 @@ void textbox_draw ( textbox *tb )
|
||||||
length = text_len + prompt_len;
|
length = text_len + prompt_len;
|
||||||
cursor_offset = MIN ( tb->cursor + prompt_len, length );
|
cursor_offset = MIN ( tb->cursor + prompt_len, length );
|
||||||
|
|
||||||
line = alloca ( length + 10 );
|
if(asprintf ( &line, "%s %s", prompt, text ) == -1) {
|
||||||
sprintf ( line, "%s %s", prompt, text );
|
// Something is _really_ wrong.. bail out
|
||||||
|
fprintf(stderr, "Failed to allocate string\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
// replace spaces so XftTextExtents8 includes their width
|
// replace spaces so XftTextExtents8 includes their width
|
||||||
for ( int i = 0; i < length; i++ )
|
for ( int i = 0; i < length; i++ )
|
||||||
|
@ -248,6 +251,10 @@ void textbox_draw ( textbox *tb )
|
||||||
// restore correct text string with spaces
|
// restore correct text string with spaces
|
||||||
sprintf ( line, "%s %s", prompt, text );
|
sprintf ( line, "%s %s", prompt, text );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line = strdup(text);
|
||||||
|
}
|
||||||
|
|
||||||
// calc full input text width
|
// calc full input text width
|
||||||
// Calculate the right size, so no characters are cut off.
|
// Calculate the right size, so no characters are cut off.
|
||||||
|
@ -289,6 +296,8 @@ void textbox_draw ( textbox *tb )
|
||||||
XftDrawRect ( draw, &tb->color_fg, cursor_x + SIDE_MARGIN, 2, cursor_width, line_height - 4 );
|
XftDrawRect ( draw, &tb->color_fg, cursor_x + SIDE_MARGIN, 2, cursor_width, line_height - 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(line);
|
||||||
|
|
||||||
XftDrawRect ( draw, &tb->color_bg, tb->w - SIDE_MARGIN, 0, SIDE_MARGIN, tb->h );
|
XftDrawRect ( draw, &tb->color_bg, tb->w - SIDE_MARGIN, 0, SIDE_MARGIN, tb->h );
|
||||||
// flip canvas to window
|
// flip canvas to window
|
||||||
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
|
XCopyArea ( display, canvas, tb->window, context, 0, 0, tb->w, tb->h, 0, 0 );
|
||||||
|
|
Loading…
Add table
Reference in a new issue