[gnome-games] playstation: Check sscanf() return value
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] playstation: Check sscanf() return value
- Date: Thu, 16 Aug 2018 09:02:42 +0000 (UTC)
commit 236b21eabd20d7327ac67b98bfeca9281a56de73
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Aug 15 00:29:33 2018 +0500
playstation: Check sscanf() return value
If sscanf() returns 0, it means that it hasn't read any data and the
string buffer is empty. In that case, don't try using it as filename.
Prevents runtime warnings in games_disc_image_get_file() and
PlayStationHeader.is_a_disc_id().
plugins/playstation/src/playstation-disc-image.c | 52 ++++++++++++++----------
1 file changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-disc-image.c
b/plugins/playstation/src/playstation-disc-image.c
index ccbc9e1e..e3bd18c6 100644
--- a/plugins/playstation/src/playstation-disc-image.c
+++ b/plugins/playstation/src/playstation-disc-image.c
@@ -25,6 +25,7 @@ games_disc_image_get_playstation_info (GamesDiscImage *disc,
guchar mdir[4096];
gchar exe_buffer[256];
gchar *ptr;
+ gint items_read;
GamesDiscFrame frame;
gboolean success;
GError *tmp_error = NULL;
@@ -81,40 +82,47 @@ games_disc_image_get_playstation_info (GamesDiscImage *disc,
// Look of "BOOT = cdrom:\\"
- sscanf ((char *) frame.mode1.content, "BOOT = cdrom:\\%255s", exe_buffer);
- success = games_disc_image_get_file (disc, (GamesDiscFileInfo *) mdir, exe_buffer, &time, cancellable,
&tmp_error);
- if (tmp_error != NULL) {
- g_propagate_error (error, tmp_error);
+ items_read = sscanf ((char *) frame.mode1.content, "BOOT = cdrom:\\%255s", exe_buffer);
- return FALSE;
- }
+ if (items_read > 0) {
+ success = games_disc_image_get_file (disc, (GamesDiscFileInfo *) mdir, exe_buffer, &time, cancellable,
&tmp_error);
- if (success) {
- if (games_disc_image_info != NULL) {
- games_disc_image_info->label = strndup (label_buffer, sizeof (label_buffer));
- games_disc_image_info->exe = strndup (exe_buffer, sizeof (exe_buffer));
+ if (tmp_error != NULL) {
+ g_propagate_error (error, tmp_error);
+
+ return FALSE;
}
- return TRUE;
+ if (success) {
+ if (games_disc_image_info != NULL) {
+ games_disc_image_info->label = strndup (label_buffer, sizeof (label_buffer));
+ games_disc_image_info->exe = strndup (exe_buffer, sizeof (exe_buffer));
+ }
+
+ return TRUE;
+ }
}
// Look of "BOOT = cdrom:"
- sscanf ((char *) frame.mode1.content, "BOOT = cdrom:%255s", exe_buffer);
- success = games_disc_image_get_file (disc, (GamesDiscFileInfo *) mdir, exe_buffer, &time, cancellable,
&tmp_error);
- if (tmp_error != NULL) {
- g_propagate_error (error, tmp_error);
+ items_read = sscanf ((char *) frame.mode1.content, "BOOT = cdrom:%255s", exe_buffer);
- return FALSE;
- }
+ if (items_read > 0) {
+ success = games_disc_image_get_file (disc, (GamesDiscFileInfo *) mdir, exe_buffer, &time, cancellable,
&tmp_error);
+ if (tmp_error != NULL) {
+ g_propagate_error (error, tmp_error);
- if (success) {
- if (games_disc_image_info != NULL) {
- games_disc_image_info->label = strndup (label_buffer, sizeof (label_buffer));
- games_disc_image_info->exe = strndup (exe_buffer, sizeof (exe_buffer));
+ return FALSE;
}
- return TRUE;
+ if (success) {
+ if (games_disc_image_info != NULL) {
+ games_disc_image_info->label = strndup (label_buffer, sizeof (label_buffer));
+ games_disc_image_info->exe = strndup (exe_buffer, sizeof (exe_buffer));
+ }
+
+ return TRUE;
+ }
}
// Look of "cdrom:"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]