Bug Summary

File:Source/Core/DiscIO/Src/VolumeGC.cpp
Location:line 152, 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
57IVolume::ECountry CVolumeGC::GetCountry() const
58{
59 if (!m_pReader)
60 return COUNTRY_UNKNOWN;
61
62 u8 CountryCode;
63 m_pReader->Read(3, 1, &CountryCode);
64
65 return CountrySwitch(CountryCode);
66}
67
68std::string CVolumeGC::GetMakerID() const
69{
70 if (m_pReader == NULL__null)
71 return std::string();
72
73 char makerID[3];
74 if (!Read(0x4, 0x2, (u8*)&makerID))
75 return std::string();
76 makerID[2] = '\0';
77
78 return makerID;
79}
80
81int CVolumeGC::GetRevision() const
82{
83 if (!m_pReader)
84 return 0;
85
86 u8 Revision;
87 if (!Read(7, 1, &Revision))
88 return 0;
89
90 return Revision;
91}
92
93std::vector<std::string> CVolumeGC::GetNames() const
94{
95 std::vector<std::string> names;
96
97 auto const string_decoder = GetStringDecoder(GetCountry());
98
99 char name[0x60 + 1] = {};
100 if (m_pReader != NULL__null && Read(0x20, 0x60, (u8*)name))
101 names.push_back(string_decoder(name));
102
103 return names;
104}
105
106u32 CVolumeGC::GetFSTSize() const
107{
108 if (m_pReader == NULL__null)
109 return 0;
110
111 u32 size;
112 if (!Read(0x428, 0x4, (u8*)&size))
113 return 0;
114
115 return Common::swap32(size);
116}
117
118std::string CVolumeGC::GetApploaderDate() const
119{
120 if (m_pReader == NULL__null)
121 return std::string();
122
123 char date[16];
124 if (!Read(0x2440, 0x10, (u8*)&date))
125 return std::string();
126 // Should be 0 already, but just in case
127 date[10] = '\0';
128
129 return date;
130}
131
132u64 CVolumeGC::GetSize() const
133{
134 if (m_pReader)
135 return m_pReader->GetDataSize();
136 else
137 return 0;
138}
139
140u64 CVolumeGC::GetRawSize() const
141{
142 if (m_pReader)
143 return m_pReader->GetRawSize();
144 else
145 return 0;
146}
147
148bool CVolumeGC::IsDiscTwo() const
149{
150 bool discTwo;
1
Variable 'discTwo' declared without an initial value
151 Read(6,1, (u8*) &discTwo);
152 return discTwo;
2
Undefined or garbage value returned to caller
153}
154
155auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder
156{
157 return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
158 SHIFTJISToUTF8 : CP1252ToUTF8;
159}
160
161} // namespace