Skip to content

Commit

Permalink
Sparse fixes: NULL use, header order, ANSI prototypes, static
Browse files Browse the repository at this point in the history
Fix Sparse warnings:
 * use NULL instead of plain 0
 * rearrange header include order to avoid redefining types accidentally
 * ANSIfy SLIRP
 * avoid "restrict" keyword
 * add static



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6736 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
blueswir1 committed Mar 7, 2009
1 parent c276471 commit 511d2b1
Show file tree
Hide file tree
Showing 35 changed files with 214 additions and 286 deletions.
2 changes: 1 addition & 1 deletion block-dmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename, int flags)
return -errno;
bs->read_only = 1;
s->n_chunks = 0;
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;

/* read offset of info blocks */
if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
Expand Down
10 changes: 5 additions & 5 deletions block-vmdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
cid_str_size = sizeof("CID");
}

if ((p_name = strstr(desc,cid_str)) != 0) {
if ((p_name = strstr(desc,cid_str)) != NULL) {
p_name += cid_str_size;
sscanf(p_name,"%x",&cid);
}
Expand All @@ -154,7 +154,7 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)

tmp_str = strstr(desc,"parentCID");
pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
if ((p_name = strstr(desc,"CID")) != 0) {
if ((p_name = strstr(desc,"CID")) != NULL) {
p_name += sizeof("CID");
snprintf(p_name, sizeof(desc) - (p_name - desc), "%x\n", cid);
pstrcat(desc, sizeof(desc), tmp_desc);
Expand Down Expand Up @@ -239,7 +239,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE)
goto fail;

if ((p_name = strstr(p_desc,"CID")) != 0) {
if ((p_name = strstr(p_desc,"CID")) != NULL) {
p_name += sizeof("CID");
sscanf(p_name,"%x",&p_cid);
}
Expand Down Expand Up @@ -330,12 +330,12 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename)
if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return -1;

if ((p_name = strstr(desc,"parentFileNameHint")) != 0) {
if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
char *end_name;
struct stat file_buf;

p_name += sizeof("parentFileNameHint") + 1;
if ((end_name = strchr(p_name,'\"')) == 0)
if ((end_name = strchr(p_name,'\"')) == NULL)
return -1;
if ((end_name - p_name) > sizeof (s->hd->backing_file) - 1)
return -1;
Expand Down
14 changes: 7 additions & 7 deletions block-vvfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct array_t {

static inline void array_init(array_t* array,unsigned int item_size)
{
array->pointer=0;
array->pointer = NULL;
array->size=0;
array->next=0;
array->item_size=item_size;
Expand Down Expand Up @@ -129,7 +129,7 @@ static inline void* array_insert(array_t* array,unsigned int index,unsigned int
int increment=count*array->item_size;
array->pointer=qemu_realloc(array->pointer,array->size+increment);
if(!array->pointer)
return 0;
return NULL;
array->size+=increment;
}
memmove(array->pointer+(index+count)*array->item_size,
Expand Down Expand Up @@ -604,8 +604,8 @@ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s,
unsigned int directory_start, const char* filename, int is_dot)
{
int i,j,long_index=s->directory.next;
direntry_t* entry=0;
direntry_t* entry_long=0;
direntry_t* entry = NULL;
direntry_t* entry_long = NULL;

if(is_dot) {
entry=array_get_next(&(s->directory));
Expand Down Expand Up @@ -696,7 +696,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
int first_cluster = mapping->begin;
int parent_index = mapping->info.dir.parent_mapping_index;
mapping_t* parent_mapping = (mapping_t*)
(parent_index >= 0 ? array_get(&(s->mapping), parent_index) : 0);
(parent_index >= 0 ? array_get(&(s->mapping), parent_index) : NULL);
int first_cluster_of_parent = parent_mapping ? parent_mapping->begin : -1;

DIR* dir=opendir(dirname);
Expand Down Expand Up @@ -1125,10 +1125,10 @@ static inline mapping_t* find_mapping_for_cluster(BDRVVVFATState* s,int cluster_
int index=find_mapping_for_cluster_aux(s,cluster_num,0,s->mapping.next);
mapping_t* mapping;
if(index>=s->mapping.next)
return 0;
return NULL;
mapping=array_get(&(s->mapping),index);
if(mapping->begin>cluster_num)
return 0;
return NULL;
assert(mapping->begin<=cluster_num && mapping->end>cluster_num);
return mapping;
}
Expand Down
4 changes: 2 additions & 2 deletions bt-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct HCIInfo *bt_host_hci(const char *id)
if (fd < 0) {
fprintf(stderr, "qemu: Can't open `%s': %s (%i)\n",
id, strerror(errno), errno);
return 0;
return NULL;
}

# ifdef CONFIG_BLUEZ
Expand All @@ -192,7 +192,7 @@ struct HCIInfo *bt_host_hci(const char *id)
s->hci.acl_send = bt_host_acl;
s->hci.bdaddr_set = bt_host_bdaddr_set;

qemu_set_fd_handler2(s->fd, bt_host_read_poll, bt_host_read, 0, s);
qemu_set_fd_handler2(s->fd, bt_host_read_poll, bt_host_read, NULL, s);

return &s->hci;
}
Expand Down
2 changes: 1 addition & 1 deletion bt-vhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ void bt_vhci_init(struct HCIInfo *info)
s->info->evt_recv = vhci_out_hci_packet_event;
s->info->acl_recv = vhci_out_hci_packet_acl;

qemu_set_fd_handler(s->fd, vhci_read, 0, s);
qemu_set_fd_handler(s->fd, vhci_read, NULL, s);
}
4 changes: 2 additions & 2 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c
unsigned height;
static int color_inited;

s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
s = new_console(ds, (p == NULL) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
if (!s) {
free(chr);
return;
Expand All @@ -1353,7 +1353,7 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c
s->y = 0;
width = ds_get_width(s->ds);
height = ds_get_height(s->ds);
if (p != 0) {
if (p != NULL) {
width = strtoul(p, (char **)&p, 10);
if (*p == 'C') {
p++;
Expand Down
9 changes: 4 additions & 5 deletions curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "qemu-common.h"
#include "console.h"
#include "sysemu.h"

#include <curses.h>

#ifndef _WIN32
Expand All @@ -38,6 +33,10 @@
#define resize_term resizeterm
#endif

#include "qemu-common.h"
#include "console.h"
#include "sysemu.h"

#define FONT_HEIGHT 16
#define FONT_WIDTH 8

Expand Down
2 changes: 1 addition & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void io_mem_init(void);
CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4];
CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4];
void *io_mem_opaque[IO_MEM_NB_ENTRIES];
char io_mem_used[IO_MEM_NB_ENTRIES];
static char io_mem_used[IO_MEM_NB_ENTRIES];
static int io_mem_watch;
#endif

Expand Down
10 changes: 5 additions & 5 deletions hw/bt-hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static inline uint8_t *bt_hci_event_start(struct bt_hci_s *hci,
mask_byte = (evt - 1) >> 3;
mask = 1 << ((evt - 1) & 3);
if (mask & bt_event_reserved_mask[mask_byte] & ~hci->event_mask[mask_byte])
return 0;
return NULL;

packet = hci->evt_packet(hci->opaque);
packet[0] = evt;
Expand Down Expand Up @@ -664,7 +664,7 @@ static void bt_hci_lmp_link_establish(struct bt_hci_s *hci,
static void bt_hci_lmp_link_teardown(struct bt_hci_s *hci, uint16_t handle)
{
handle &= ~HCI_HANDLE_OFFSET;
hci->lm.handle[handle].link = 0;
hci->lm.handle[handle].link = NULL;

if (bt_hci_role_master(hci, handle)) {
qemu_del_timer(hci->lm.handle[handle].acl_mode_timer);
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static void bt_hci_reset(struct bt_hci_s *hci)
hci->device.page_scan = 0;
if (hci->device.lmp_name)
qemu_free((void *) hci->device.lmp_name);
hci->device.lmp_name = 0;
hci->device.lmp_name = NULL;
hci->device.class[0] = 0x00;
hci->device.class[1] = 0x00;
hci->device.class[2] = 0x00;
Expand Down Expand Up @@ -1617,7 +1617,7 @@ static void bt_submit_hci(struct HCIInfo *info,

bt_hci_event_status(hci, HCI_SUCCESS);
bt_hci_connection_accept(hci, hci->conn_req_host);
hci->conn_req_host = 0;
hci->conn_req_host = NULL;
break;

case cmd_opcode_pack(OGF_LINK_CTL, OCF_REJECT_CONN_REQ):
Expand All @@ -1634,7 +1634,7 @@ static void bt_submit_hci(struct HCIInfo *info,
bt_hci_connection_reject(hci, hci->conn_req_host,
PARAM(reject_conn_req, reason));
bt_hci_connection_reject_event(hci, &hci->conn_req_host->bd_addr);
hci->conn_req_host = 0;
hci->conn_req_host = NULL;
break;

case cmd_opcode_pack(OGF_LINK_CTL, OCF_AUTH_REQUESTED):
Expand Down
9 changes: 5 additions & 4 deletions hw/bt-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ static void bt_hid_control_transaction(struct bt_hid_device_s *s,
break;
}
s->proto = parameter;
s->usbdev->handle_control(s->usbdev, SET_PROTOCOL, s->proto, 0, 0, 0);
s->usbdev->handle_control(s->usbdev, SET_PROTOCOL, s->proto, 0, 0,
NULL);
ret = BT_HS_SUCCESSFUL;
break;

Expand All @@ -347,7 +348,7 @@ static void bt_hid_control_transaction(struct bt_hid_device_s *s,
/* We don't need to know about the Idle Rate here really,
* so just pass it on to the device. */
ret = s->usbdev->handle_control(s->usbdev,
SET_IDLE, data[1], 0, 0, 0) ?
SET_IDLE, data[1], 0, 0, NULL) ?
BT_HS_SUCCESSFUL : BT_HS_ERR_INVALID_PARAMETER;
/* XXX: Does this generate a handshake? */
break;
Expand Down Expand Up @@ -462,15 +463,15 @@ static void bt_hid_close_control(void *opaque)
{
struct bt_hid_device_s *hid = opaque;

hid->control = 0;
hid->control = NULL;
bt_hid_connected_update(hid);
}

static void bt_hid_close_interrupt(void *opaque)
{
struct bt_hid_device_s *hid = opaque;

hid->interrupt = 0;
hid->interrupt = NULL;
bt_hid_connected_update(hid);
}

Expand Down
8 changes: 4 additions & 4 deletions hw/bt-l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static inline struct bt_l2cap_psm_s *l2cap_psm(
static struct l2cap_chan_s *l2cap_channel_open(struct l2cap_instance_s *l2cap,
int psm, int source_cid)
{
struct l2cap_chan_s *ch = 0;
struct l2cap_chan_s *ch = NULL;
struct bt_l2cap_psm_s *psm_info;
int result, status;
int cid = l2cap_cid_new(l2cap);
Expand Down Expand Up @@ -452,7 +452,7 @@ static struct l2cap_chan_s *l2cap_channel_open(struct l2cap_instance_s *l2cap,
static void l2cap_channel_close(struct l2cap_instance_s *l2cap,
int cid, int source_cid)
{
struct l2cap_chan_s *ch = 0;
struct l2cap_chan_s *ch = NULL;

/* According to Volume 3, section 6.1.1, pg 1048 of BT Core V2.0, a
* connection in CLOSED state still responds with a L2CAP_DisconnectRsp
Expand All @@ -472,7 +472,7 @@ static void l2cap_channel_close(struct l2cap_instance_s *l2cap,
return;
}

l2cap->cid[cid] = 0;
l2cap->cid[cid] = NULL;

ch->params.close(ch->params.opaque);
qemu_free(ch);
Expand All @@ -484,7 +484,7 @@ static void l2cap_channel_close(struct l2cap_instance_s *l2cap,
static void l2cap_channel_config_null(struct l2cap_instance_s *l2cap,
struct l2cap_chan_s *ch)
{
l2cap_configuration_request(l2cap, ch->remote_cid, 0, 0, 0);
l2cap_configuration_request(l2cap, ch->remote_cid, 0, NULL, 0);
ch->config_req_id = l2cap->last_id;
ch->config &= ~L2CAP_CFG_INIT;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/bt-sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
&sdp_service_sdp_s,
&sdp_service_hid_s,
&sdp_service_pnp_s,
0,
NULL,
};

sdp->channel = params;
Expand Down
2 changes: 2 additions & 0 deletions hw/ppce500_mpc8544ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define MPC8544_PCI_IO 0xE1000000
#define MPC8544_PCI_IOLEN 0x10000

#ifdef HAVE_FDT
static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop)
{
uint32_t cell;
Expand All @@ -68,6 +69,7 @@ static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop)
out:
return ret;
}
#endif

static void *mpc8544_load_device_tree(void *addr,
uint32_t ramsize,
Expand Down
6 changes: 3 additions & 3 deletions hw/usb-bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@ static void usb_bt_handle_destroy(USBDevice *dev)
{
struct USBBtState *s = (struct USBBtState *) dev->opaque;

s->hci->opaque = 0;
s->hci->evt_recv = 0;
s->hci->acl_recv = 0;
s->hci->opaque = NULL;
s->hci->evt_recv = NULL;
s->hci->acl_recv = NULL;
qemu_free(s);
}

Expand Down
11 changes: 10 additions & 1 deletion hw/vmware_vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ enum {
#ifdef VERBOSE
# define GUEST_OS_BASE 0x5001
static const char *vmsvga_guest_id[] = {
[0x00 ... 0x15] = "an unknown OS",
[0x00] = "Dos",
[0x01] = "Windows 3.1",
[0x02] = "Windows 95",
Expand All @@ -240,8 +239,18 @@ static const char *vmsvga_guest_id[] = {
[0x06] = "Windows 2000",
[0x07] = "Linux",
[0x08] = "OS/2",
[0x09] = "an unknown OS",
[0x0a] = "BSD",
[0x0b] = "Whistler",
[0x0c] = "an unknown OS",
[0x0d] = "an unknown OS",
[0x0e] = "an unknown OS",
[0x0f] = "an unknown OS",
[0x10] = "an unknown OS",
[0x11] = "an unknown OS",
[0x12] = "an unknown OS",
[0x13] = "an unknown OS",
[0x14] = "an unknown OS",
[0x15] = "Windows 2003",
};
#endif
Expand Down
4 changes: 2 additions & 2 deletions hw/wm8750.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ static void wm8750_set_format(struct wm8750_s *s)
for (i = 0; i < IN_PORT_N; i ++)
if (s->adc_voice[i]) {
AUD_close_in(&s->card, s->adc_voice[i]);
s->adc_voice[i] = 0;
s->adc_voice[i] = NULL;
}
for (i = 0; i < OUT_PORT_N; i ++)
if (s->dac_voice[i]) {
AUD_close_out(&s->card, s->dac_voice[i]);
s->dac_voice[i] = 0;
s->dac_voice[i] = NULL;
}

if (!s->enable)
Expand Down
2 changes: 1 addition & 1 deletion monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <dirent.h>
#include "hw/hw.h"
#include "hw/usb.h"
#include "hw/pcmcia.h"
Expand All @@ -37,7 +38,6 @@
#include "audio/audio.h"
#include "disas.h"
#include "balloon.h"
#include <dirent.h>
#include "qemu-timer.h"
#include "migration.h"
#include "kvm.h"
Expand Down
Loading

0 comments on commit 511d2b1

Please sign in to comment.