Bug Summary

File:Source/Core/DiscIO/Src/VolumeGC.cpp
Location:line 159, column 2
Description:Undefined or garbage value returned to caller

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "stdafx.h"
6
7#include "VolumeGC.h"
8#include "StringUtil.h"
9#include "FileMonitor.h"
10
11namespace DiscIO
12{
13CVolumeGC::CVolumeGC(IBlobReader* _pReader)
14 : m_pReader(_pReader)
15{}
16
17CVolumeGC::~CVolumeGC()
18{
19 delete m_pReader;
20 m_pReader = NULL__null; // I don't think this makes any difference, but anyway
21}
22
23bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
24{
25 if (m_pReader == NULL__null)
26 return false;
27
28 FileMon::FindFilename(_Offset);
29
30 return m_pReader->Read(_Offset, _Length, _pBuffer);
31}
32
33bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const
34{
35 return Read(_Offset, _Length, _pBuffer);
36}
37
38std::string CVolumeGC::GetUniqueID() const
39{
40 static const std::string NO_UID("NO_UID");
41 if (m_pReader == NULL__null)
42 return NO_UID;
43
44 char ID[7];
45
46 if (!Read(0, sizeof(ID), reinterpret_cast<u8*>(ID)))
47 {
48 PanicAlertT("Failed to read unique ID from disc image")MsgAlert(false, WARNING, "Failed to read unique ID from disc image"
)
;
49 return NO_UID;
50 }
51
52 ID[6] = '\0';
53
54 return ID;
55}
56
57std::string CVolumeGC::GetRevisionSpecificUniqueID() const
58{
59 char rev[16];
60 sprintf(rev, "r%d", GetRevision());
61 return GetUniqueID() + rev;
62}
63
64IVolume::ECountry CVolumeGC::GetCountry() const
65{
66 if (!m_pReader)
67 return COUNTRY_UNKNOWN;
68
69 u8 CountryCode;
70 m_pReader->Read(3, 1, &CountryCode);
71
72 return CountrySwitch(CountryCode);
73}
74
75std::string CVolumeGC::GetMakerID() const
76{
77 if (m_pReader == NULL__null)
78 return std::string();
79
80 char makerID[3];
81 if (!Read(0x4, 0x2, (u8*)&makerID))
82 return std::string();
83 makerID[2] = '\0';
84
85 return makerID;
86}
87
88int CVolumeGC::GetRevision() const
89{
90 if (!m_pReader)
91 return 0;
92
93 u8 Revision;
94 if (!Read(7, 1, &Revision))
95 return 0;
96
97 return Revision;
98}
99
100std::vector<std::string> CVolumeGC::GetNames() const
101{
102 std::vector<std::string> names;
103
104 auto const string_decoder = GetStringDecoder(GetCountry());
105
106 char name[0x60 + 1] = {};
107 if (m_pReader != NULL__null && Read(0x20, 0x60, (u8*)name))
108 names.push_back(string_decoder(name));
109
110 return names;
111}
112
113u32 CVolumeGC::GetFSTSize() const
114{
115 if (m_pReader == NULL__null)
116 return 0;
117
118 u32 size;
119 if (!Read(0x428, 0x4, (u8*)&size))
120 return 0;
121
122 return Common::swap32(size);
123}
124
125std::string CVolumeGC::GetApploaderDate() const
126{
127 if (m_pReader == NULL__null)
128 return std::string();
129
130 char date[16];
131 if (!Read(0x2440, 0x10, (u8*)&date))
132 return std::string();
133 // Should be 0 already, but just in case
134 date[10] = '\0';
135
136 return date;
137}
138
139u64 CVolumeGC::GetSize() const
140{
141 if (m_pReader)
142 return m_pReader->GetDataSize();
143 else
144 return 0;
145}
146
147u64 CVolumeGC::GetRawSize() const
148{
149 if (m_pReader)
150 return m_pReader->GetRawSize();
151 else
152 return 0;
153}
154
155bool CVolumeGC::IsDiscTwo() const
156{
157 bool discTwo;
1
'discTwo' declared without an initial value
158 Read(6,1, (u8*) &discTwo);
159 return discTwo;
2
Undefined or garbage value returned to caller
160}
161
162auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder
163{
164 return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
165 SHIFTJISToUTF8 : CP1252ToUTF8;
166}
167
168} // namespace