envy24control: fix cast warnings and string array overflows

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2025-01-26 12:40:23 +01:00
parent 54b5913cd5
commit 97092591e0
7 changed files with 20 additions and 16 deletions

View file

@ -46,7 +46,7 @@ void config_close()
void config_set_stereo(GtkWidget *but, gpointer data)
{
gint i=(gint)data;
gint i=GPOINTER_TO_INT(data);
config_stereo[i]=GTK_TOGGLE_BUTTON(but)->active;
}

View file

@ -249,7 +249,7 @@ static void create_mixer_frame(GtkWidget *box, int stream)
gtk_box_pack_end(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
/* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), TRUE); */
gtk_signal_connect(GTK_OBJECT(toggle), "toggled",
GTK_SIGNAL_FUNC(config_set_stereo), (gpointer)stream-1);
GTK_SIGNAL_FUNC(config_set_stereo), GINT_TO_POINTER(stream-1));
hbox = gtk_hbox_new(TRUE, 6);
gtk_widget_show(hbox);
@ -2176,7 +2176,7 @@ int main(int argc, char **argv)
if (! name) {
/* probe cards */
static char cardname[8];
static char cardname[16];
/* FIXME: hardcoded max number of cards */
for (card_number = 0; card_number < 8; card_number++) {
sprintf(cardname, "hw:%d", card_number);

View file

@ -65,7 +65,7 @@ static GdkGC *get_pen(int idx, int nRed, int nGreen, int nBlue)
return gc;
}
static int get_index(gchar *name)
static int get_index(const gchar *name)
{
int result;

View file

@ -20,9 +20,9 @@ int new_process(char * const cmd_line[MAX_PARAM])
struct stat file_status;
/* memory for storage of function pointers from the signal handling routines */
void (*int_stat)();
void (*quit_stat)();
void (*usr2_stat)();
void (*int_stat)(int);
void (*quit_stat)(int);
void (*usr2_stat)(int);
/*
* check command file

View file

@ -54,9 +54,9 @@ void subst_tilde_in_filename(char * const filename)
if ((pos_after_tilde = strchr(filename, '~')) != NULL) {
pos_after_tilde++;
strncpy(new_filename, getenv("HOME"), MAX_FILE_NAME_LENGTH);
strncpy(new_filename + strlen(new_filename), pos_after_tilde, MAX_FILE_NAME_LENGTH - strlen(new_filename));
new_filename[MAX_FILE_NAME_LENGTH - 1] = '\0';
strncpy(new_filename, getenv("HOME"), sizeof(new_filename) - 1);
strncpy(new_filename + strlen(new_filename), pos_after_tilde, sizeof(new_filename) - strlen(new_filename) - 1);
new_filename[sizeof(new_filename) - 1] = '\0';
strncpy(filename, new_filename, MAX_FILE_NAME_LENGTH);
}
}
@ -522,7 +522,7 @@ int reorganize_profiles(char * const buffer, const int max_length)
{
int profile_number, card_number, card_number_max;
int res;
int pos_profile_begin, pos_profile_end, pos_card_begin, pos_card_end, pos_name_header;
int pos_profile_begin, pos_card_begin, pos_card_end, pos_name_header;
int pos_alsa_section_begin, pos_after_alsa_section;
char header[MAX_SEARCH_FIELD_LENGTH];
void *buffer_copy = NULL;
@ -547,7 +547,6 @@ int reorganize_profiles(char * const buffer, const int max_length)
compose_search_string(header, PROFILE_HEADER_TEMPL, profile_or_card_number_as_str, place_holder, MAX_SEARCH_FIELD_LENGTH);
header[MAX_SEARCH_FIELD_LENGTH - 1] = '\0';
snprintf(buffer_copy + strlen(buffer_copy), max_length - strlen(buffer_copy), "%s\n", header);
pos_profile_end = get_profile_end(buffer, profile_number);
/* search max card number in profile */
card_number_max = get_max_card_number_in_profile(buffer, profile_number);
for (card_number = 0; card_number <= card_number_max; card_number++)
@ -641,9 +640,9 @@ int save_restore_alsactl_settings(char * const tmpfile, const int card_number, c
void compose_tmpfile_name(char * const tmpfile, const char * const cfgfile)
{
strncpy(tmpfile, cfgfile, MAX_FILE_NAME_LENGTH);
strncpy(tmpfile, cfgfile, MAX_FILE_NAME_LENGTH - 1);
tmpfile[MAX_FILE_NAME_LENGTH - 1] = '\0';
strncpy(tmpfile + strlen(tmpfile), "_alsactl_tmp", MAX_FILE_NAME_LENGTH - strlen(tmpfile));
strncpy(tmpfile + strlen(tmpfile), "_alsactl_tmp", MAX_FILE_NAME_LENGTH - strlen(tmpfile) - 1);
tmpfile[MAX_FILE_NAME_LENGTH - 1] = '\0';
}

View file

@ -44,7 +44,7 @@
#define MAX_PROFILE_SIZE 32768
#define MAX_SEARCH_FIELD_LENGTH 1024
#define MAX_FILE_NAME_LENGTH 1024
#define MAX_NUM_STR_LENGTH 10
#define MAX_NUM_STR_LENGTH 11
#define TOKEN_SEP "|"
#define SEP_CHAR ' '

View file

@ -48,6 +48,7 @@ int strstr_icase_blank(const char * const string1, const char * const string2)
char search_string[MAX_SEARCH_FIELD_LENGTH];
char *pstr;
int pos_first_non_blank;
size_t len;
strncpy(search_string, string2, MAX_SEARCH_FIELD_LENGTH);
search_string[MAX_SEARCH_FIELD_LENGTH - 1] = '\0';
@ -84,7 +85,11 @@ int strstr_icase_blank(const char * const string1, const char * const string2)
}
}
}
strncpy(search_string, cmp_line, strlen(search_string));
len = strlen(search_string);
if (len > sizeof(search_string) - 1)
len = sizeof(search_string) - 1;
strncpy(search_string, cmp_line, len);
search_string[len] = '\0';
position = 0;
while (position < strlen(string1))