comparison src/cdaudio-ng/cdaudio-ng.c @ 1967:600972dea2ac

got did of sprintf's() and strcpy's()
author Calin Crisan ccrisan@gmail.com
date Wed, 03 Oct 2007 02:47:26 +0300
parents 3fef1171cd6c
children 5fa26178eaef 33d6f1dc7cfb
comparison
equal deleted inserted replaced
1959:3fef1171cd6c 1967:600972dea2ac
162 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cdtext", &use_cdtext)) 162 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cdtext", &use_cdtext))
163 use_cdtext = TRUE; 163 use_cdtext = TRUE;
164 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &use_cddb)) 164 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &use_cddb))
165 use_cddb = TRUE; 165 use_cddb = TRUE;
166 if (!bmp_cfg_db_get_string(db, "CDDA", "cddbserver", &string)) 166 if (!bmp_cfg_db_get_string(db, "CDDA", "cddbserver", &string))
167 strcpy(cddb_server, CDDA_DEFAULT_CDDB_SERVER); 167 strncpy(cddb_server, CDDA_DEFAULT_CDDB_SERVER, strlen(CDDA_DEFAULT_CDDB_SERVER) + 1);
168 else 168 else
169 strcpy(cddb_server, string); 169 strncpy(cddb_server, string, strlen(string) + 1);
170 if (!bmp_cfg_db_get_int(db, "CDDA", "cddbport", &cddb_port)) 170 if (!bmp_cfg_db_get_int(db, "CDDA", "cddbport", &cddb_port))
171 cddb_port = CDDA_DEFAULT_CDDB_PORT; 171 cddb_port = CDDA_DEFAULT_CDDB_PORT;
172 if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string)) 172 if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string))
173 strcpy(device, ""); 173 strcpy(device, "");
174 else 174 else
175 strcpy(device, string); 175 strncpy(device, string, strlen(device) + 1);
176 if (!bmp_cfg_db_get_bool(db, "CDDA", "debug", &use_debug)) 176 if (!bmp_cfg_db_get_bool(db, "CDDA", "debug", &use_debug))
177 use_debug = FALSE; 177 use_debug = FALSE;
178 178
179 bmp_cfg_db_close(db); 179 bmp_cfg_db_close(db);
180 180
393 pcddb_disc = NULL; 393 pcddb_disc = NULL;
394 } 394 }
395 else { 395 else {
396 CDDEBUG("we have got the cddb info\n"); 396 CDDEBUG("we have got the cddb info\n");
397 397
398 strcpy(trackinfo[0].performer, cddb_disc_get_artist(pcddb_disc)); 398 strncpy(trackinfo[0].performer, cddb_disc_get_artist(pcddb_disc), strlen(cddb_disc_get_artist(pcddb_disc)) + 1);
399 strcpy(trackinfo[0].name, cddb_disc_get_title(pcddb_disc)); 399 strncpy(trackinfo[0].name, cddb_disc_get_title(pcddb_disc), strlen(cddb_disc_get_title(pcddb_disc)) + 1);
400 strcpy(trackinfo[0].genre, cddb_disc_get_genre(pcddb_disc)); 400 strncpy(trackinfo[0].genre, cddb_disc_get_genre(pcddb_disc), strlen(cddb_disc_get_genre(pcddb_disc)) + 1);
401 } 401 }
402 } 402 }
403 } 403 }
404 } 404 }
405 405
409 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, 0); 409 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, 0);
410 if (pcdtext == NULL || pcdtext->field[CDTEXT_TITLE] == NULL) { 410 if (pcdtext == NULL || pcdtext->field[CDTEXT_TITLE] == NULL) {
411 CDDEBUG("no cd-text available for disc\n"); 411 CDDEBUG("no cd-text available for disc\n");
412 } 412 }
413 else { 413 else {
414 strcpy(trackinfo[0].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); 414 strncpy(trackinfo[0].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : "", strlen(pcdtext->field[CDTEXT_PERFORMER]) + 1);
415 strcpy(trackinfo[0].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); 415 strncpy(trackinfo[0].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : "", strlen(pcdtext->field[CDTEXT_TITLE]) + 1);
416 strcpy(trackinfo[0].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); 416 strncpy(trackinfo[0].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : "", strlen(pcdtext->field[CDTEXT_GENRE]) + 1);
417 } 417 }
418 } 418 }
419 419
420 /* add track "file" names to the list */ 420 /* add track "file" names to the list */
421 GList *list = NULL; 421 GList *list = NULL;
430 pcdtext = NULL; 430 pcdtext = NULL;
431 } 431 }
432 } 432 }
433 433
434 if (pcdtext != NULL) { 434 if (pcdtext != NULL) {
435 strcpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); 435 strncpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : "", strlen(pcdtext->field[CDTEXT_PERFORMER]) + 1);
436 strcpy(trackinfo[trackno].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); 436 strncpy(trackinfo[trackno].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : "", strlen(pcdtext->field[CDTEXT_TITLE]) + 1);
437 strcpy(trackinfo[trackno].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); 437 strncpy(trackinfo[trackno].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : "", strlen(pcdtext->field[CDTEXT_GENRE]) + 1);
438 } 438 }
439 else 439 else
440 if (pcddb_disc != NULL) { 440 if (pcddb_disc != NULL) {
441 cddb_track_t *pcddb_track = cddb_disc_get_track(pcddb_disc, trackno - 1); 441 cddb_track_t *pcddb_track = cddb_disc_get_track(pcddb_disc, trackno - 1);
442 strcpy(trackinfo[trackno].performer, cddb_track_get_artist(pcddb_track)); 442 strncpy(trackinfo[trackno].performer, cddb_track_get_artist(pcddb_track), strlen(cddb_track_get_artist(pcddb_track)) + 1);
443 strcpy(trackinfo[trackno].name, cddb_track_get_title(pcddb_track)); 443 strncpy(trackinfo[trackno].name, cddb_track_get_title(pcddb_track), strlen(cddb_track_get_title(pcddb_track)) + 1);
444 strcpy(trackinfo[trackno].genre, cddb_disc_get_genre(pcddb_disc)); 444 strncpy(trackinfo[trackno].genre, cddb_disc_get_genre(pcddb_disc), strlen(cddb_disc_get_genre(pcddb_disc)) + 1);
445 } 445 }
446 else { 446 else {
447 strcpy(trackinfo[trackno].performer, ""); 447 strcpy(trackinfo[trackno].performer, "");
448 strcpy(trackinfo[trackno].name, ""); 448 strcpy(trackinfo[trackno].name, "");
449 strcpy(trackinfo[trackno].genre, ""); 449 strcpy(trackinfo[trackno].genre, "");
450 } 450 }
451 451
452 if (strlen(trackinfo[trackno].name) == 0) 452 if (strlen(trackinfo[trackno].name) == 0)
453 sprintf(trackinfo[trackno].name, "CD Audio Track %02u", trackno); 453 snprintf(trackinfo[trackno].name, trackno, "CD Audio Track %02u", sizeof(trackinfo[trackno].name));
454 454
455 } 455 }
456 456
457 if (use_debug) { 457 if (use_debug) {
458 CDDEBUG("disc has : performer = \"%s\", name = \"%s\", genre = \"%s\"\n", 458 CDDEBUG("disc has : performer = \"%s\", name = \"%s\", genre = \"%s\"\n",
921 return ((endlsn - startlsn + 1) * 1000) / 75; 921 return ((endlsn - startlsn + 1) * 1000) / 75;
922 } 922 }
923 923
924 static gint find_trackno_from_filename(gchar *filename) 924 static gint find_trackno_from_filename(gchar *filename)
925 { 925 {
926 gchar tracknostr[3]; 926 gchar tracknostr[DEF_STRING_LEN];
927 if ((filename == NULL) || strlen(filename) <= 6) 927 if ((filename == NULL) || strlen(filename) <= 6)
928 return -1; 928 return -1;
929 929
930 strncpy(tracknostr, filename + strlen(filename) - 6, 2); 930 strncpy(tracknostr, filename + strlen(filename) - 6, 2);
931 tracknostr[2] = '\0'; 931 tracknostr[2] = '\0';