Bug Summary

File:Source/Core/DiscIO/Src/BannerLoaderWii.cpp
Location:line 27, column 12
Description:Function call argument is an uninitialized value

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <stdio.h>
6#include <algorithm>
7
8#include "Common.h"
9#include "ColorUtil.h"
10#include "BannerLoaderWii.h"
11#include "VolumeCreator.h"
12#include "FileUtil.h"
13#include "FileHandlerARC.h"
14
15namespace DiscIO
16{
17
18CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
19 : m_pBannerFile(NULL__null)
20 , m_IsValid(false)
21{
22 char Filename[260];
23 u64 TitleID;
1
Variable 'TitleID' declared without an initial value
24
25 pVolume->GetTitleID((u8*)&TitleID);
26
27 TitleID = Common::swap64(TitleID);
2
Function call argument is an uninitialized value
28
29 sprintf(Filename, "%stitle/%08x/%08x/data/banner.bin",
30 File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
31
32 if (!File::Exists(Filename))
33 {
34 // TODO(XK): Finish the 'commented' code. Turns out the banner.bin
35 // from the savefiles is very different from the banner.bin
36 // inside opening.bnr
37#if 0
38 char bnrFilename[260], titleFolder[260];
39
40 // Creating title folder
41 sprintf(titleFolder, "%stitle/%08x/%08x/data/",
42 File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
43 if(!File::Exists(titleFolder))
44 File::CreateFullPath(titleFolder);
45
46 // Extracting banner.bin from opening.bnr
47 sprintf(bnrFilename, "%stitle/%08x/%08x/data/opening.bnr",
48 File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
49
50 if(!_rFileSystem.ExportFile("opening.bnr", bnrFilename)) {
51 m_IsValid = false;
52 return;
53 }
54
55 CARCFile bnrArc (bnrFilename, 0x600);
56
57 if(!bnrArc.ExportFile("meta/banner.bin", Filename)) {
58 m_IsValid = false;
59 return;
60 }
61
62 // Now we have an LZ77-compressed file with a short IMD5 header
63 // TODO: Finish the job
64
65 File::Delete(bnrFilename);
66#else
67 m_IsValid = false;
68 return;
69#endif
70 }
71
72 // load the banner.bin
73 size_t FileSize = (size_t) File::GetSize(Filename);
74
75 if (FileSize > 0)
76 {
77 m_pBannerFile = new u8[FileSize];
78 File::IOFile pFile(Filename, "rb");
79 if (pFile)
80 {
81 pFile.ReadBytes(m_pBannerFile, FileSize);
82 m_IsValid = true;
83 }
84 }
85}
86
87CBannerLoaderWii::~CBannerLoaderWii()
88{
89 if (m_pBannerFile)
90 {
91 delete [] m_pBannerFile;
92 m_pBannerFile = NULL__null;
93 }
94}
95
96bool CBannerLoaderWii::IsValid()
97{
98 return m_IsValid;
99}
100
101static inline u32 Average32(u32 a, u32 b) {
102 return ((a >> 1) & 0x7f7f7f7f) + ((b >> 1) & 0x7f7f7f7f);
103}
104
105static inline u32 GetPixel(u32 *buffer, unsigned int x, unsigned int y) {
106 // thanks to unsignedness, these also check for <0 automatically.
107 if (x > 191) return 0;
108 if (y > 63) return 0;
109 return buffer[y * 192 + x];
110}
111
112bool CBannerLoaderWii::GetBanner(u32* _pBannerImage)
113{
114 if (IsValid())
115 {
116 SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
117 u32* Buffer = new u32[192 * 64];
118 decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64);
119 for (int y = 0; y < 32; y++)
120 {
121 for (int x = 0; x < 96; x++)
122 {
123 // simplified plus-shaped "gaussian"
124 u32 surround = Average32(
125 Average32(GetPixel(Buffer, x*2 - 1, y*2), GetPixel(Buffer, x*2 + 1, y*2)),
126 Average32(GetPixel(Buffer, x*2, y*2 - 1), GetPixel(Buffer, x*2, y*2 + 1)));
127 _pBannerImage[y * 96 + x] = Average32(GetPixel(Buffer, x*2, y*2), surround);
128 }
129 }
130 delete[] Buffer;
131 }
132 return true;
133}
134
135bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
136{
137 if (IsValid())
138 {
139 auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
140 auto const src_ptr = banner->m_Comment[index];
141
142 // Trim at first NULL
143 auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;
144
145 std::wstring src;
146 src.resize(length);
147 std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16);
148 result = UTF16ToUTF8(src);
149
150 return true;
151 }
152
153 return false;
154}
155
156std::vector<std::string> CBannerLoaderWii::GetNames()
157{
158 std::vector<std::string> ret(1);
159
160 if (!GetStringFromComments(NAME_IDX, ret[0]))
161 ret.clear();
162
163 return ret;
164}
165
166std::string CBannerLoaderWii::GetCompany()
167{
168 return "";
169}
170
171std::vector<std::string> CBannerLoaderWii::GetDescriptions()
172{
173 std::vector<std::string> result(1);
174 if (!GetStringFromComments(DESC_IDX, result[0]))
175 result.clear();
176 return result;
177}
178
179void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
180{
181 for (int y = 0; y < height; y += 4)
182 {
183 for (int x = 0; x < width; x += 4)
184 {
185 for (int iy = 0; iy < 4; iy++, src += 4)
186 {
187 for (int ix = 0; ix < 4; ix++)
188 {
189 u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
190 dst[(y + iy) * width + (x + ix)] = RGBA;
191 }
192 }
193 }
194 }
195}
196
197} // namespace