Cleanup: use braces around statements

This commit is contained in:
Campbell Barton 2023-09-12 14:48:20 +10:00
parent f942f64b1d
commit 057c9364fc
20 changed files with 125 additions and 63 deletions

View File

@ -65,8 +65,9 @@ GHOST_ContextWGL::~GHOST_ContextWGL()
s_sharedCount--;
if (s_sharedCount == 0)
if (s_sharedCount == 0) {
s_sharedHGLRC = nullptr;
}
WIN32_CHK(::wglDeleteContext(m_hGLRC));
}
@ -88,10 +89,12 @@ GHOST_TSuccess GHOST_ContextWGL::swapBuffers()
GHOST_TSuccess GHOST_ContextWGL::setSwapInterval(int interval)
{
if (epoxy_has_wgl_extension(m_hDC, "WGL_EXT_swap_control"))
if (epoxy_has_wgl_extension(m_hDC, "WGL_EXT_swap_control")) {
return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
else
}
else {
return GHOST_kFailure;
}
}
GHOST_TSuccess GHOST_ContextWGL::getSwapInterval(int &intervalOut)
@ -149,8 +152,9 @@ static int weight_pixel_format(PIXELFORMATDESCRIPTOR &pfd, PIXELFORMATDESCRIPTOR
weight += pfd.cColorBits - 8;
if (preferredPFD.cAlphaBits > 0 && pfd.cAlphaBits > 0)
if (preferredPFD.cAlphaBits > 0 && pfd.cAlphaBits > 0) {
weight++;
}
#ifdef WIN32_COMPOSITING
if ((preferredPFD.dwFlags & PFD_SUPPORT_COMPOSITION) && (pfd.dwFlags & PFD_SUPPORT_COMPOSITION))
weight++;
@ -200,8 +204,9 @@ static int choose_pixel_format_legacy(HDC hDC, PIXELFORMATDESCRIPTOR &preferredP
}
/* choose any available stereo format over a non-stereo format */
if (iStereoPixelFormat != 0)
if (iStereoPixelFormat != 0) {
iPixelFormat = iStereoPixelFormat;
}
if (iPixelFormat == 0) {
fprintf(stderr, "Warning! Using result of ChoosePixelFormat.\n");
@ -372,36 +377,44 @@ struct DummyContextWGL {
dummyPixelFormat = choose_pixel_format_legacy(hDC, preferredPFD);
if (dummyPixelFormat == 0)
if (dummyPixelFormat == 0) {
return;
}
PIXELFORMATDESCRIPTOR chosenPFD;
if (!WIN32_CHK(::DescribePixelFormat(
hDC, dummyPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD)))
{
return;
}
if (hWnd) {
dummyHWND = clone_window(hWnd, nullptr);
if (dummyHWND == nullptr)
if (dummyHWND == nullptr) {
return;
}
dummyHDC = GetDC(dummyHWND);
}
if (!WIN32_CHK(dummyHDC != nullptr))
if (!WIN32_CHK(dummyHDC != nullptr)) {
return;
}
if (!WIN32_CHK(::SetPixelFormat(dummyHDC, dummyPixelFormat, &chosenPFD)))
if (!WIN32_CHK(::SetPixelFormat(dummyHDC, dummyPixelFormat, &chosenPFD))) {
return;
}
dummyHGLRC = ::wglCreateContext(dummyHDC);
if (!WIN32_CHK(dummyHGLRC != nullptr))
if (!WIN32_CHK(dummyHGLRC != nullptr)) {
return;
}
if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC)))
if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC))) {
return;
}
has_WGL_ARB_pixel_format = epoxy_has_wgl_extension(hDC, "WGL_ARB_pixel_format");
has_WGL_ARB_create_context = epoxy_has_wgl_extension(hDC, "WGL_ARB_create_context");
@ -523,8 +536,9 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
if (!dummy.has_WGL_ARB_create_context || ::GetPixelFormat(m_hDC) == 0) {
int iPixelFormat = 0;
if (dummy.has_WGL_ARB_pixel_format)
if (dummy.has_WGL_ARB_pixel_format) {
iPixelFormat = choose_pixel_format_arb(m_stereoVisual, needAlpha);
}
if (iPixelFormat == 0)
iPixelFormat = choose_pixel_format_legacy(m_hDC, dummy.preferredPFD);
@ -541,8 +555,9 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
goto error;
}
if (needAlpha && chosenPFD.cAlphaBits == 0)
if (needAlpha && chosenPFD.cAlphaBits == 0) {
fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n");
}
if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) {
goto error;
@ -553,22 +568,27 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
int profileBitCore = m_contextProfileMask & WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
int profileBitCompat = m_contextProfileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
if (!dummy.has_WGL_ARB_create_context_profile && profileBitCore)
if (!dummy.has_WGL_ARB_create_context_profile && profileBitCore) {
fprintf(stderr, "Warning! OpenGL core profile not available.\n");
}
if (!dummy.has_WGL_ARB_create_context_profile && profileBitCompat)
if (!dummy.has_WGL_ARB_create_context_profile && profileBitCompat) {
fprintf(stderr, "Warning! OpenGL compatibility profile not available.\n");
}
int profileMask = 0;
if (dummy.has_WGL_ARB_create_context_profile && profileBitCore)
if (dummy.has_WGL_ARB_create_context_profile && profileBitCore) {
profileMask |= profileBitCore;
}
if (dummy.has_WGL_ARB_create_context_profile && profileBitCompat)
if (dummy.has_WGL_ARB_create_context_profile && profileBitCompat) {
profileMask |= profileBitCompat;
}
if (profileMask != m_contextProfileMask)
if (profileMask != m_contextProfileMask) {
fprintf(stderr, "Warning! Ignoring untested OpenGL context profile mask bits.");
}
std::vector<int> iAttributes;

View File

@ -41,8 +41,9 @@ GHOST_TSuccess GHOST_DisplayManagerWin32::getNumDisplaySettings(uint8_t display,
* function was called with #iModeNum set to zero. */
DISPLAY_DEVICE display_device;
if (!get_dd(display, &display_device))
if (!get_dd(display, &display_device)) {
return GHOST_kFailure;
}
numSettings = 0;
DEVMODE dm;
@ -57,8 +58,9 @@ GHOST_TSuccess GHOST_DisplayManagerWin32::getDisplaySetting(uint8_t display,
GHOST_DisplaySetting &setting) const
{
DISPLAY_DEVICE display_device;
if (!get_dd(display, &display_device))
if (!get_dd(display, &display_device)) {
return GHOST_kFailure;
}
GHOST_TSuccess success;
DEVMODE dm;
@ -102,8 +104,9 @@ GHOST_TSuccess GHOST_DisplayManagerWin32::setCurrentDisplaySetting(
uint8_t display, const GHOST_DisplaySetting &setting)
{
DISPLAY_DEVICE display_device;
if (!get_dd(display, &display_device))
if (!get_dd(display, &display_device)) {
return GHOST_kFailure;
}
GHOST_DisplaySetting match;
findMatch(display, setting, match);

View File

@ -130,8 +130,9 @@ void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filepath) const
IShellItem *shell_item;
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (!SUCCEEDED(hr))
if (!SUCCEEDED(hr)) {
return;
}
hr = SHCreateItemFromParsingName(filepath_16, nullptr, IID_PPV_ARGS(&shell_item));
if (SUCCEEDED(hr)) {

View File

@ -2734,8 +2734,9 @@ void GHOST_SystemX11::refreshXInputDevices()
void GHOST_SystemX11::clearXInputDevices()
{
for (GHOST_TabletX11 &xtablet : m_xtablets) {
if (xtablet.Device)
if (xtablet.Device) {
XCloseDevice(m_display, xtablet.Device);
}
}
m_xtablets.clear();

View File

@ -671,8 +671,9 @@ void GHOST_WindowWin32::updateMouseCapture(GHOST_MouseCaptureEventWin32 event)
m_nPressedButtons++;
break;
case MouseReleased:
if (m_nPressedButtons)
if (m_nPressedButtons) {
m_nPressedButtons--;
}
break;
case OperatorGrab:
m_hasGrabMouse = true;
@ -821,12 +822,14 @@ HCURSOR GHOST_WindowWin32::getStandardCursor(GHOST_TStandardCursor shape) const
void GHOST_WindowWin32::loadCursor(bool visible, GHOST_TStandardCursor shape) const
{
if (!visible) {
while (::ShowCursor(FALSE) >= 0)
;
while (::ShowCursor(FALSE) >= 0) {
/* Pass. */
}
}
else {
while (::ShowCursor(TRUE) < 0)
;
while (::ShowCursor(TRUE) < 0) {
/* Pass. */
}
}
HCURSOR cursor = getStandardCursor(shape);

View File

@ -402,8 +402,9 @@ bool GHOST_WindowX11::createX11_XIC()
XNDestroyCallback,
&destroy,
nullptr);
if (!m_xic)
if (!m_xic) {
return false;
}
ulong fevent;
XGetICValues(m_xic, XNFilterEvents, &fevent, nullptr);

View File

@ -397,8 +397,9 @@ bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData)
break;
case GHOST_kEventWindowUpdate: {
GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent);
if (!GHOST_ValidWindow(shSystem, window2))
if (!GHOST_ValidWindow(shSystem, window2)) {
break;
}
setViewPortGL(window2);
drawGL();
GHOST_SwapWindowBuffers(window2);

View File

@ -602,8 +602,9 @@ bool Application::processEvent(GHOST_IEvent *event)
case GHOST_kEventWindowUpdate: {
GHOST_IWindow *window2 = event->getWindow();
if (!m_system->validWindow(window2))
if (!m_system->validWindow(window2)) {
break;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@ -78,10 +78,12 @@ void rect_bevel_side(int rect[2][2], int side, float *lt, float *dk, const float
int x = (corner == 0 || corner == 1) ? (rect[0][0] + i) : (rect[1][0] - i - 1);
int y = (corner == 0 || corner == 3) ? (rect[0][1] + i) : (rect[1][1] - i - 1);
if (ltidx == corner)
if (ltidx == corner) {
glColor3f(col[0] * ltf, col[1] * ltf, col[2] * ltf);
if (dkidx == corner)
}
if (dkidx == corner) {
glColor3f(col[0] * dkf, col[1] * dkf, col[2] * dkf);
}
glVertex2i(lx, ly);
glVertex2i(lx = x, ly = y);
@ -513,8 +515,9 @@ static void loggerwindow_do_key(LoggerWindow *lw, GHOST_TKey key, int press)
{
switch (key) {
case GHOST_kKeyQ:
if (press)
if (press) {
multitestapp_exit(lw->app);
}
break;
}
}
@ -685,8 +688,9 @@ static void extrawindow_do_key(ExtraWindow *ew, GHOST_TKey key, int press)
{
switch (key) {
case GHOST_kKeyE:
if (press)
if (press) {
multitestapp_toggle_extra_window(ew->app);
}
break;
}
}
@ -862,19 +866,23 @@ MultiTestApp *multitestapp_new(void)
GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(multitest_event_handler, app);
app->sys = GHOST_CreateSystem();
if (!app->sys)
if (!app->sys) {
fatal("Unable to create ghost system");
}
if (!GHOST_AddEventConsumer(app->sys, consumer))
if (!GHOST_AddEventConsumer(app->sys, consumer)) {
fatal("Unable to add multitest event consumer ");
}
app->main = mainwindow_new(app);
if (!app->main)
if (!app->main) {
fatal("Unable to create main window");
}
app->logger = loggerwindow_new(app);
if (!app->logger)
if (!app->logger) {
fatal("Unable to create logger window");
}
app->extra = NULL;
app->exit = 0;

View File

@ -34,12 +34,14 @@ void *operator new[](size_t size)
void operator delete(void *p) throw()
{
/* delete NULL is valid in c++ */
if (p)
if (p) {
MEM_freeN(p);
}
}
void operator delete[](void *p) throw()
{
/* delete NULL is valid in c++ */
if (p)
if (p) {
MEM_freeN(p);
}
}

View File

@ -39,8 +39,9 @@ int main(int argc, char *argv[])
switch (argc) {
case 2:
verbose = atoi(argv[1]);
if (verbose < 0)
if (verbose < 0) {
verbose = 0;
}
break;
case 1:
default:
@ -59,15 +60,17 @@ int main(int argc, char *argv[])
for (i = 0; i < NUM_BLOCKS; i++) {
int blocksize = 10000;
char tagstring[1000];
if (verbose > 1)
if (verbose > 1) {
printf("|--* Allocating block %d\n", i);
}
sprintf(tagstring, "Memblock no. %d : ", i);
p[i] = MEM_callocN(blocksize, strdup(tagstring));
}
/* report on that */
if (verbose > 1)
if (verbose > 1) {
MEM_printmemlist();
}
/* memory is there: test it */
error_status = MEM_consistency_check();
@ -94,16 +97,18 @@ int main(int argc, char *argv[])
for (i = 0; i < NUM_BLOCKS; i++) {
int blocksize = 10000;
char tagstring[1000];
if (verbose > 1)
if (verbose > 1) {
printf("|--* Allocating block %d\n", i);
}
sprintf(tagstring, "Memblock no. %d : ", i);
p[i] = MEM_callocN(blocksize, strdup(tagstring));
}
/* Now corrupt a few blocks. */
ip = (int *)p[5] - 50;
for (i = 0; i < 1000; i++, ip++)
for (i = 0; i < 1000; i++, ip++) {
*ip = i + 1;
}
ip = (int *)p[6];
*(ip + 10005) = 0;

View File

@ -227,8 +227,9 @@ static void bli_windows_system_backtrace_modules(FILE *fp)
{
fprintf(fp, "Loaded Modules :\n");
HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
if (hModuleSnap == INVALID_HANDLE_VALUE)
if (hModuleSnap == INVALID_HANDLE_VALUE) {
return;
}
MODULEENTRY32 me32;
me32.dwSize = sizeof(MODULEENTRY32);

View File

@ -573,8 +573,9 @@ void blo_readfile_invalidate(FileData *fd, Main *bmain, const char *message)
/* Tag given `bmain`, and 'root 'local' main one (in case given one is a library one) as invalid.
*/
bmain->is_read_invalid = true;
for (; bmain->prev != nullptr; bmain = bmain->prev)
;
for (; bmain->prev != nullptr; bmain = bmain->prev) {
/* Pass. */
}
bmain->is_read_invalid = true;
BLO_reportf_wrap(fd->reports,

View File

@ -263,8 +263,9 @@ static int strip_modifier_copy_exec(bContext *C, wmOperator *op)
/* If original is sound, only copy to "sound" strips
* If original is not sound, only copy to "not sound" strips
*/
if (isSound != seq_iter_is_sound)
if (isSound != seq_iter_is_sound) {
continue;
}
if (type == SEQ_MODIFIER_COPY_REPLACE) {
if (seq_iter->modifiers.first) {

View File

@ -137,8 +137,9 @@ static void generate_vertex_map(const Mesh *mesh,
/* Add zero UVs for any loose vertices. */
for (int vertex_index = 0; vertex_index < mesh->totvert; vertex_index++) {
if (r_vertex_to_ply[vertex_index] != -1)
if (r_vertex_to_ply[vertex_index] != -1) {
continue;
}
int ply_index = int(r_uvs.size());
r_vertex_to_ply[vertex_index] = ply_index;
r_uvs.append({0, 0});

View File

@ -60,8 +60,9 @@ static Span<char> parse_word(Span<char> &str)
static void skip_space(Span<char> &str)
{
while (!str.is_empty() && str[0] <= ' ')
while (!str.is_empty() && str[0] <= ' ') {
str = str.drop_front(1);
}
}
static PlyDataTypes type_from_string(Span<char> word)

View File

@ -64,8 +64,9 @@ bool PlyReadBuffer::read_bytes(void *dst, size_t size)
}
}
int to_copy = int(size);
if (to_copy > buf_used_)
if (to_copy > buf_used_) {
to_copy = buf_used_;
}
memcpy(dst, buffer_.data() + pos_, to_copy);
pos_ += to_copy;
dst = (char *)dst + to_copy;

View File

@ -341,8 +341,9 @@ static uint32_t read_list_count(PlyReadBuffer &file,
scratch.resize(8);
file.read_bytes(scratch.data(), data_type_size[prop.count_type]);
const uint8_t *ptr = scratch.data();
if (big_endian)
if (big_endian) {
endian_switch((uint8_t *)ptr, data_type_size[prop.count_type]);
}
uint32_t count = get_binary_value<uint32_t>(prop.count_type, ptr);
return count;
}
@ -446,8 +447,9 @@ static const char *load_face_element(PlyReadBuffer &file,
scratch.resize(count * data_type_size[prop.type]);
file.read_bytes(scratch.data(), scratch.size());
ptr = scratch.data();
if (header.type == PlyFormatType::BINARY_BE)
if (header.type == PlyFormatType::BINARY_BE) {
endian_switch_array((uint8_t *)ptr, data_type_size[prop.type], count);
}
for (int j = 0; j < count; ++j) {
uint32_t index = get_binary_value<uint32_t>(prop.type, ptr);
data->face_vertices.append(index);
@ -508,8 +510,9 @@ static const char *load_tristrips_element(PlyReadBuffer &file,
scratch.resize(count * data_type_size[prop.type]);
file.read_bytes(scratch.data(), scratch.size());
ptr = scratch.data();
if (header.type == PlyFormatType::BINARY_BE)
if (header.type == PlyFormatType::BINARY_BE) {
endian_switch_array((uint8_t *)ptr, data_type_size[prop.type], count);
}
for (int j = 0; j < count; ++j) {
int index = get_binary_value<int>(prop.type, ptr);
strip[j] = index;

View File

@ -76,7 +76,7 @@ static std::unique_ptr<PlyData> load_cube(PLYExportParams &params)
plyData->face_vertices = {0, 2, 6, 4, 3, 7, 6, 2, 7, 5, 4, 6,
5, 7, 3, 1, 1, 3, 2, 0, 5, 1, 0, 4};
if (params.export_normals)
if (params.export_normals) {
plyData->vertex_normals = {
{-0.5773503, -0.5773503, -0.5773503},
{-0.5773503, -0.5773503, 0.5773503},
@ -87,6 +87,7 @@ static std::unique_ptr<PlyData> load_cube(PLYExportParams &params)
{0.5773503, 0.5773503, -0.5773503},
{0.5773503, 0.5773503, 0.5773503},
};
}
return plyData;
}

View File

@ -161,10 +161,12 @@ EQCurveMappingData *SEQ_sound_equalizer_add(SoundEqualizerModifierData *semd,
{
EQCurveMappingData *eqcmd;
if (maxX < 0)
if (maxX < 0) {
maxX = SOUND_EQUALIZER_DEFAULT_MAX_FREQ;
if (minX < 0)
}
if (minX < 0) {
minX = 0.0;
}
/* It's the same as BKE_curvemapping_add , but changing the name */
eqcmd = MEM_cnew<EQCurveMappingData>("Equalizer");
BKE_curvemapping_set_defaults(&eqcmd->curve_mapping,
@ -212,12 +214,15 @@ EQCurveMappingData *SEQ_sound_equalizermodifier_add_graph(SoundEqualizerModifier
float min_freq,
float max_freq)
{
if (min_freq < 0.0)
if (min_freq < 0.0) {
return nullptr;
if (max_freq < 0.0)
}
if (max_freq < 0.0) {
return nullptr;
if (max_freq <= min_freq)
}
if (max_freq <= min_freq) {
return nullptr;
}
return SEQ_sound_equalizer_add(semd, min_freq, max_freq);
}
@ -327,8 +332,9 @@ void *SEQ_sound_equalizermodifier_recreator(Sequence *seq, SequenceModifierData
const SoundModifierWorkerInfo *SEQ_sound_modifier_worker_info_get(int type)
{
for (int i = 0; workersSoundModifiers[i].type > 0; i++) {
if (workersSoundModifiers[i].type == type)
if (workersSoundModifiers[i].type == type) {
return &workersSoundModifiers[i];
}
}
return nullptr;
}