more cleanups (unused/uninitialized variables, forgotten free()s, etc.)

This commit is contained in:
Christian Bauer 2012-09-02 13:52:28 +02:00
parent c1e7267de4
commit b4940ae29d
16 changed files with 106 additions and 66 deletions

View File

@ -650,14 +650,15 @@ static bool handle_selection(XSelectionRequestEvent *req, bool is_multiple)
{
bool handled =false;
if (req->target == xa_timestamp)
if (req->target == xa_timestamp) {
handled = handle_selection_TIMESTAMP(req);
else if (req->target == xa_targets)
} else if (req->target == xa_targets) {
handled = handle_selection_TARGETS(req);
else if (req->target == XA_STRING)
} else if (req->target == XA_STRING) {
handled = handle_selection_STRING(req);
else if (req->target == xa_multiple)
} else if (req->target == xa_multiple) {
handled = handle_selection_MULTIPLE(req);
}
// Notify requestor only when we are done with his request
if (handled && !is_multiple) {
@ -666,7 +667,7 @@ static bool handle_selection(XSelectionRequestEvent *req, bool is_multiple)
out_event.xselection.requestor = req->requestor;
out_event.xselection.selection = req->selection;
out_event.xselection.target = req->target;
out_event.xselection.property = handled ? req->property : None;
out_event.xselection.property = req->property;
out_event.xselection.time = req->time;
XSendEvent(x_display, req->requestor, False, 0, &out_event);
}

View File

@ -96,7 +96,9 @@ enum {
};
// Constants
#if ENABLE_TUNTAP
static const char ETHERCONFIG_FILE_NAME[] = DATADIR "/tunconfig";
#endif
// Global variables
static int fd = -1; // fd of sheep_net device
@ -650,11 +652,13 @@ static int16 ether_do_add_multicast(uint8 *addr)
case NET_IF_SHEEPNET:
if (ioctl(fd, SIOCADDMULTI, addr) < 0) {
D(bug("WARNING: Couldn't enable multicast address\n"));
if (net_if_type == NET_IF_ETHERTAP)
if (net_if_type == NET_IF_ETHERTAP) {
return noErr;
else
} else {
return eMultiErr;
}
}
return noErr;
default:
return noErr;
}
@ -674,6 +678,7 @@ static int16 ether_do_del_multicast(uint8 *addr)
D(bug("WARNING: Couldn't disable multicast address\n"));
return eMultiErr;
}
return noErr;
default:
return noErr;
}

View File

@ -388,5 +388,3 @@ const char *macroman_to_host_encoding(const char *filename)
{
return filename;
}

View File

@ -200,7 +200,6 @@ static GtkWidget *table_make_option_menu(GtkWidget *table, int row, int label_id
static GtkWidget *table_make_combobox(GtkWidget *table, int row, int label_id, const char *default_value, GList *glist)
{
GtkWidget *label, *combo;
char str[32];
label = gtk_label_new(GetString(label_id));
gtk_widget_show(label);
@ -654,7 +653,7 @@ static void read_volumes_settings(void)
// Create "Volumes" pane
static void create_volumes_pane(GtkWidget *top)
{
GtkWidget *box, *scroll, *menu;
GtkWidget *box, *scroll;
box = make_pane(top, STR_VOLUMES_PANE_TITLE);
@ -696,7 +695,7 @@ static void create_volumes_pane(GtkWidget *top)
case 0: active = 0; break;
case CDROMRefNum: active = 1; break;
}
menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
}
@ -707,7 +706,6 @@ static void create_volumes_pane(GtkWidget *top)
*/
static GtkWidget *w_jit_fpu;
static GtkWidget *w_jit_atraps;
static GtkWidget *w_jit_cache_size;
static GtkWidget *w_jit_lazy_flush;
static GtkWidget *w_jit_follow_const_jumps;
@ -784,8 +782,7 @@ static void create_jit_pane(GtkWidget *top)
if (!is_jit_capable())
return;
GtkWidget *box, *table, *label, *menu;
char str[32];
GtkWidget *box;
box = make_pane(top, STR_JIT_PANE_TITLE);
make_checkbox(box, STR_JIT_CTRL, "jit", GTK_SIGNAL_FUNC(tb_jit));
@ -1163,7 +1160,7 @@ static void read_input_settings(void)
// Create "Input" pane
static void create_input_pane(GtkWidget *top)
{
GtkWidget *box, *hbox, *menu, *label, *button;
GtkWidget *box, *hbox, *label, *button;
GtkObject *adj;
box = make_pane(top, STR_INPUT_PANE_TITLE);
@ -1203,7 +1200,7 @@ static void create_input_pane(GtkWidget *top)
case 0: active = 0; break;
case 1: active = 1; break;
}
menu = make_option_menu(box, STR_MOUSEWHEELMODE_CTRL, options, active);
make_option_menu(box, STR_MOUSEWHEELMODE_CTRL, options, active);
hbox = gtk_hbox_new(FALSE, 4);
gtk_widget_show(hbox);
@ -1475,7 +1472,7 @@ static void read_memory_settings(void)
// Create "Memory/Misc" pane
static void create_memory_pane(GtkWidget *top)
{
GtkWidget *box, *hbox, *table, *label, *menu;
GtkWidget *box, *table;
box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE);
table = make_table(box, 2, 5);

View File

@ -196,12 +196,14 @@ rpc_connection_t *rpc_init_server(const char *ident)
if (bind(connection->server_socket, (struct sockaddr *)&addr, addr_len) < 0) {
perror("server bind");
close(connection->socket);
free(connection);
return NULL;
}
if (listen(connection->server_socket, 1) < 0) {
perror("server listen");
close(connection->socket);
free(connection);
return NULL;
}
@ -253,6 +255,7 @@ rpc_connection_t *rpc_init_client(const char *ident)
break;
if (n_connect_attempts > 1 && errno != ECONNREFUSED && errno != ENOENT) {
perror("client_connect");
close(connection->socket);
free(connection);
return NULL;
}
@ -260,6 +263,7 @@ rpc_connection_t *rpc_init_client(const char *ident)
usleep(N_CONNECT_WAIT_DELAY);
}
if (n_connect_attempts == 0) {
close(connection->socket);
free(connection);
return NULL;
}
@ -780,13 +784,15 @@ int rpc_message_recv_string(rpc_message_t *message, char **ret)
if ((error = _rpc_message_recv_bytes(message, (unsigned char *)&r_value, sizeof(r_value))) < 0)
return error;
length = ntohl(r_value);
if (length == 0)
if (length == 0) {
str = NULL;
else {
} else {
if ((str = (char *)malloc(length + 1)) == NULL)
return RPC_ERROR_NO_MEMORY;
if ((error = _rpc_message_recv_bytes(message, (unsigned char *)str, length)) < 0)
if ((error = _rpc_message_recv_bytes(message, (unsigned char *)str, length)) < 0) {
free(str);
return error;
}
str[length] = '\0';
}
*ret = str;
@ -838,8 +844,10 @@ static int rpc_message_recv_args(rpc_message_t *message, va_list args)
if ((array = (unsigned char *)malloc(array_size * sizeof(*array))) == NULL)
return RPC_ERROR_NO_MEMORY;
error = _rpc_message_recv_bytes(message, array, array_size);
if (error != RPC_ERROR_NO_ERROR)
if (error != RPC_ERROR_NO_ERROR) {
free(array);
return error;
}
*((void **)p_value) = (void *)array;
break;
}
@ -850,8 +858,10 @@ static int rpc_message_recv_args(rpc_message_t *message, va_list args)
return RPC_ERROR_NO_MEMORY;
for (i = 0; i < array_size; i++) {
int32_t value;
if ((error = rpc_message_recv_int32(message, &value)) < 0)
if ((error = rpc_message_recv_int32(message, &value)) < 0) {
free(array);
return error;
}
array[i] = value;
}
*((void **)p_value) = (void *)array;
@ -863,8 +873,10 @@ static int rpc_message_recv_args(rpc_message_t *message, va_list args)
return RPC_ERROR_NO_MEMORY;
for (i = 0; i < array_size; i++) {
uint32_t value;
if ((error = rpc_message_recv_uint32(message, &value)) < 0)
if ((error = rpc_message_recv_uint32(message, &value)) < 0) {
free(array);
return error;
}
array[i] = value;
}
*((void **)p_value) = (void *)array;
@ -876,8 +888,10 @@ static int rpc_message_recv_args(rpc_message_t *message, va_list args)
return RPC_ERROR_NO_MEMORY;
for (i = 0; i < array_size; i++) {
char *str;
if ((error = rpc_message_recv_string(message, &str)) < 0)
if ((error = rpc_message_recv_string(message, &str)) < 0) {
free(array);
return error;
}
array[i] = str;
}
*((void **)p_value) = (void *)array;
@ -889,8 +903,10 @@ static int rpc_message_recv_args(rpc_message_t *message, va_list args)
if ((array = (char *)malloc(array_size * desc->size)) == NULL)
return RPC_ERROR_NO_MEMORY;
for (i = 0; i < array_size; i++) {
if ((error = desc->recv_callback(message, &array[i * desc->size])) < 0)
if ((error = desc->recv_callback(message, &array[i * desc->size])) < 0) {
free(array);
return error;
}
}
*((void **)p_value) = array;
}

View File

@ -38,6 +38,7 @@
#include <list>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include "sigsegv.h"
#ifndef NO_STD_NAMESPACE
@ -1060,11 +1061,13 @@ static bool ix86_skip_instruction(SIGSEGV_REGISTER_TYPE * regs)
#endif
case 0x02: // ADD r8, r/m8
transfer_size = SIZE_BYTE;
// fall through
case 0x03: // ADD r32, r/m32
instruction_type = i_ADD;
goto do_transfer_load;
case 0x8a: // MOV r8, r/m8
transfer_size = SIZE_BYTE;
// fall through
case 0x8b: // MOV r32, r/m32 (or 16-bit operation)
do_transfer_load:
switch (eip[op_len] & 0xc0) {
@ -1085,11 +1088,13 @@ static bool ix86_skip_instruction(SIGSEGV_REGISTER_TYPE * regs)
break;
case 0x00: // ADD r/m8, r8
transfer_size = SIZE_BYTE;
// fall through
case 0x01: // ADD r/m32, r32
instruction_type = i_ADD;
goto do_transfer_store;
case 0x88: // MOV r/m8, r8
transfer_size = SIZE_BYTE;
// fall through
case 0x89: // MOV r/m32, r32 (or 16-bit operation)
do_transfer_store:
switch (eip[op_len] & 0xc0) {
@ -2857,6 +2862,7 @@ static bool sigsegv_do_install_handler(int sig)
// Setup SIGSEGV handler to process writes to frame buffer
#ifdef HAVE_SIGACTION
struct sigaction sigsegv_sa;
memset(&sigsegv_sa, 0, sizeof(struct sigaction));
sigemptyset(&sigsegv_sa.sa_mask);
sigsegv_sa.sa_sigaction = sigsegv_handler;
sigsegv_sa.sa_flags = SA_SIGINFO;
@ -2873,6 +2879,7 @@ static bool sigsegv_do_install_handler(int sig)
// Setup SIGSEGV handler to process writes to frame buffer
#ifdef HAVE_SIGACTION
struct sigaction sigsegv_sa;
memset(&sigsegv_sa, 0, sizeof(struct sigaction));
sigemptyset(&sigsegv_sa.sa_mask);
sigsegv_sa.sa_handler = (signal_handler)sigsegv_handler;
sigsegv_sa.sa_flags = 0;

View File

@ -386,6 +386,7 @@ static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 b
mode.resolution_id = resolution_id;
mode.bytes_per_row = bytes_per_row;
mode.depth = depth;
mode.user_data = 0;
VideoModes.push_back(mode);
}
@ -707,7 +708,8 @@ void driver_base::restore_mouse_accel(void)
// Open display
driver_window::driver_window(X11_monitor_desc &m)
: driver_base(m), gc(0), img(NULL), have_shm(false), mac_cursor(0), mouse_grabbed(false)
: driver_base(m), gc(0), img(NULL), have_shm(false), mac_cursor(0),
mouse_grabbed(false), mouse_last_x(0), mouse_last_y(0)
{
int width = mode.x, height = mode.y;
int aligned_width = (width + 15) & ~15;
@ -2271,9 +2273,10 @@ static void update_display_dynamic(int ticker, driver_window *drv)
y2s = sm_uptd[ticker % 8];
y2a = 8;
for (i = 0; i < 6; i++)
for (i = 0; i < 6; i++) {
if (ticker % (2 << i))
break;
}
max_box = sm_no_boxes[i];
if (y2a) {

View File

@ -466,11 +466,13 @@ int16 CDROMPrime(uint32 pb, uint32 dce)
// Yes, fake (otherwise audio CDs won't get mounted)
memset(buffer, 0, 0x200);
actual = 0x200;
} else
} else {
return readErr;
}
}
} else
} else {
return wPrErr;
}
// Update ParamBlock and DCE
WriteMacInt32(pb + ioActCount, actual);
@ -500,7 +502,7 @@ int16 CDROMControl(uint32 pb, uint32 dce)
return noErr;
}
case 81: // Set poll freq
case 81: // Set poll freq
WriteMacInt16(dce + dCtlDelay, ReadMacInt16(pb + csParam));
return noErr;
}
@ -508,10 +510,11 @@ int16 CDROMControl(uint32 pb, uint32 dce)
// Drive valid?
drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
if (info == drives.end()) {
if (drives.empty())
if (drives.empty()) {
return nsDrvErr;
else
} else {
info = drives.begin(); // This is needed for Apple's Audio CD program
}
}
// Drive-specific codes
@ -539,15 +542,15 @@ int16 CDROMControl(uint32 pb, uint32 dce)
WriteMacInt32(pb + csParam, CDROMIconAddr);
return noErr;
case 23: // drive_info
case 23: // GetDriveInfo
WriteMacInt32(pb + csParam, 0x00000b01); // Unspecified external removable SCSI disk
return noErr;
case 70: { // SetPowerMode
uint8 mode = ReadMacInt8(pb + csParam);
if (mode > 3)
if (mode > 3) {
return paramErr;
else {
} else {
info->power_mode = mode;
return noErr;
}
@ -560,9 +563,9 @@ int16 CDROMControl(uint32 pb, uint32 dce)
case 79: { // Change block size
uint16 size = ReadMacInt16(pb + csParam);
D(bug(" change block size to %d bytes\n", size));
if (size != 512 && size != 2048)
if (size != 512 && size != 2048) {
return paramErr;
else {
} else {
info->block_size = size;
return noErr;
}
@ -575,8 +578,9 @@ int16 CDROMControl(uint32 pb, uint32 dce)
else
SysPreventRemoval(info->fh);
return noErr;
} else
} else {
return offLinErr;
}
case 100: { // ReadTOC
if (ReadMacInt8(info->status + dsDiskInPlace) == 0)
@ -611,7 +615,7 @@ int16 CDROMControl(uint32 pb, uint32 dce)
}
// Fill buffer
if (i != 804)
if (i != 804) {
while (buf_size > 0) {
WriteMacInt8(buf, info->toc[i+1] & 0x0f); buf++; // Control
WriteMacInt8(buf, bin2bcd[info->toc[i+5]]); buf++; // M
@ -625,6 +629,7 @@ int16 CDROMControl(uint32 pb, uint32 dce)
buf_size -= 4;
i += 8;
}
}
break;
}
@ -665,8 +670,9 @@ int16 CDROMControl(uint32 pb, uint32 dce)
WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs)
WriteMacInt8(p, 0);
return noErr;
} else
} else {
return ioErr;
}
}
case 102: // ReadHeader
@ -786,10 +792,11 @@ int16 CDROMControl(uint32 pb, uint32 dce)
if (!position2msf(*info, ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), false, start_m, start_s, start_f))
return paramErr;
if (!SysCDScan(info->fh, start_m, start_s, start_f, ReadMacInt16(pb + csParam + 6)))
if (!SysCDScan(info->fh, start_m, start_s, start_f, ReadMacInt16(pb + csParam + 6))) {
return paramErr;
else
} else {
return noErr;
}
}
case 109: // AudioControl
@ -805,7 +812,7 @@ int16 CDROMControl(uint32 pb, uint32 dce)
return controlErr;
case 112: { // ReadAudioVolume
uint8 left, right;
uint8 left = 0, right = 0;
SysCDGetVolume(info->fh, left, right);
WriteMacInt8(pb + csParam, left);
WriteMacInt8(pb + csParam + 1, right);
@ -940,8 +947,9 @@ int16 CDROMStatus(uint32 pb, uint32 dce)
WriteMacInt32(adr, SysGetFileSize(info->fh) / 512); // Number of blocks
WriteMacInt32(adr + 4, 0); // heads/track/sectors
return noErr;
} else
} else {
return paramErr;
}
case 8: // DriveStatus
Mac2Mac_memcpy(pb + csParam, info->status, 22);
@ -955,8 +963,9 @@ int16 CDROMStatus(uint32 pb, uint32 dce)
if (info->twok_offset > 0) {
WriteMacInt16(pb + csParam, info->twok_offset);
return noErr;
} else
} else {
return statusErr;
}
case 96: // Get drive type
WriteMacInt16(pb + csParam, 3); // Apple CD 300 or newer

View File

@ -327,7 +327,7 @@ int16 EtherControl(uint32 pb, uint32 dce)
// Extract destination address
uint32 dest_ip;
if (packet[0] == 'B' && packet[1] == '2')
if (len >= 6 && packet[0] == 'B' && packet[1] == '2')
dest_ip = (packet[2] << 24) | (packet[3] << 16) | (packet[4] << 8) | packet[5];
else if (is_apple_talk_broadcast(packet) || is_ethernet_broadcast(packet))
dest_ip = INADDR_BROADCAST;

View File

@ -820,9 +820,9 @@ static int16 get_current_dir(uint32 pb, uint32 dirID, uint32 &current_dir, bool
break;
case dtmvWDRefNum: // Determined by working directory refNum
if (dirID)
if (dirID) {
current_dir = dirID;
else {
} else {
D(bug(" resolving WDCB\n"));
r.d[0] = 0;
r.d[1] = 0;
@ -838,9 +838,9 @@ static int16 get_current_dir(uint32 pb, uint32 dirID, uint32 &current_dir, bool
break;
case dtmvDefault: // Determined by default volume
if (dirID)
if (dirID) {
current_dir = dirID;
else {
} else {
uint32 wdpb = fs_data + fsReturn;
WriteMacInt32(wdpb + ioNamePtr, 0);
D(bug(" getting default volume\n"));

View File

@ -1011,7 +1011,6 @@ static bool patch_rom_classic(void)
// ROM patches for 32-bit clean Mac-II ROMs (version $067c)
static bool patch_rom_32(void)
{
uint32 *lp;
uint16 *wp;
uint8 *bp;
uint32 base;

View File

@ -115,10 +115,11 @@ static int16 exec_tib(uint32 tib)
switch (cmd) {
case scInc:
WriteMacInt32(tib - 8, ptr + len);
// fall through to scNoInc
case scNoInc:
if ((sg_index > 0) && (Mac2HostAddr(ptr) == sg_ptr[sg_index-1] + sg_len[sg_index-1]))
if ((sg_index > 0) && (Mac2HostAddr(ptr) == sg_ptr[sg_index-1] + sg_len[sg_index-1])) {
sg_len[sg_index-1] += len; // Merge to previous entry
else {
} else {
if (sg_index == SG_TABLE_SIZE) {
ErrorAlert(GetString(STR_SCSI_SG_FULL_ERR));
return -108;
@ -208,21 +209,20 @@ int16 SCSISelect(int id)
return scSequenceErr;
// ID valid?
if (id >= 0 && id <= 7) {
target_id = id;
if (id < 0 || id > 7)
return scBadParmsErr;
// Target present?
if (scsi_is_target_present(target_id)) {
phase = PH_SELECTED;
fake_status = 0x006a; // Target selected, command phase
return 0;
}
// Target present?
target_id = id;
if (!scsi_is_target_present(target_id)) {
phase = PH_FREE;
fake_status = 0x0000; // Bus free
return scCommErr;
}
// Error
phase = PH_FREE;
fake_status = 0x0000; // Bus free
return scCommErr;
phase = PH_SELECTED;
fake_status = 0x006a; // Target selected, command phase
return 0;
}

View File

@ -333,6 +333,7 @@ fork_exec(so, ex, do_pty)
return 0;
}
} else {
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = 0;
addr.sin_addr.s_addr = INADDR_ANY;

View File

@ -575,6 +575,7 @@ solisten(port, laddr, lport, flags)
so->so_lport = lport; /* Kept in network format */
so->so_laddr.s_addr = laddr; /* Ditto */
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = port;

View File

@ -400,6 +400,7 @@ int tcp_fconnect(so)
if( (ret=so->s=socket(AF_INET,SOCK_STREAM,0)) >= 0) {
int opt, s=so->s;
struct sockaddr_in addr;
memset(&addr, 0, sizeof(struct sockaddr_in));
fd_nonblock(s);
opt = 1;

View File

@ -333,6 +333,7 @@ udp_attach(so)
* (sendto() on an unbound socket will bind it), it's done
* here so that emulation of ytalk etc. don't have to do it
*/
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = 0;
addr.sin_addr.s_addr = INADDR_ANY;
@ -645,6 +646,7 @@ udp_listen(port, laddr, lport, flags)
so->so_expire = curtime + SO_EXPIRE;
insque(so,&udb);
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = port;