Skip to content

Commit

Permalink
Merge pull request FreeRDP#473 from kiilerix/master
Browse files Browse the repository at this point in the history
misc
  • Loading branch information
awakecoding committed Feb 28, 2012
2 parents 3e5a978 + 9c8f5d6 commit 54b26c4
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 56 deletions.
4 changes: 2 additions & 2 deletions client/Windows/wfreerdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ boolean wf_post_connect(freerdp* instance)
if (settings->window_title != NULL)
_snwprintf(win_title, sizeof(win_title), L"%S", settings->window_title);
else if (settings->port == 3389)
_snwprintf(win_title, sizeof(win_title) / sizeof(win_title[0]), L"FreeRDP: %S", settings->hostname);
_snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S", settings->hostname);
else
_snwprintf(win_title, sizeof(win_title) / sizeof(win_title[0]), L"FreeRDP: %S:%d", settings->hostname, settings->port);
_snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S:%d", settings->hostname, settings->port);

if (wfi->hwnd == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_cliprdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ static void xf_cliprdr_append_target(clipboardContext* cb, Atom target)
{
int i;

if (cb->num_targets >= sizeof(cb->targets) / sizeof(Atom))
if (cb->num_targets >= ARRAY_SIZE(cb->targets))
return;

for (i = 0; i < cb->num_targets; i++)
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height,
input_mask |= EnterWindowMask | LeaveWindowMask;

XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_ICON, XA_CARDINAL, 32,
PropModeReplace, (uint8*) xf_icon_prop, sizeof(xf_icon_prop) / sizeof(long));
PropModeReplace, (uint8*) xf_icon_prop, ARRAY_SIZE(xf_icon_prop));

XSelectInput(xfi->display, window->handle, input_mask);
XMapWindow(xfi->display, window->handle);
Expand Down
10 changes: 5 additions & 5 deletions cunit/test_rail.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ static uint8 server_app_get_resp_app_id[] =


#define EMULATE_SERVER_SEND_CHANNEL_DATA(inst, byte_array) \
emulate_server_send_channel_data(inst, byte_array, RAIL_ARRAY_SIZE(byte_array))
emulate_server_send_channel_data(inst, byte_array, ARRAY_SIZE(byte_array))

#define STREAM_EQUAL_TO_DUMP(stream, dump) \
(stream_equal_dump((stream)->data, (stream)->size, dump, RAIL_ARRAY_SIZE(dump)))
(stream_equal_dump((stream)->data, (stream)->size, dump, ARRAY_SIZE(dump)))

#define UNICODE_STRING_EQUAL_TO_DUMP(ustring, dump) \
(stream_equal_dump((ustring)->string, (ustring)->length, dump, RAIL_ARRAY_SIZE(dump)))
(stream_equal_dump((ustring)->string, (ustring)->length, dump, ARRAY_SIZE(dump)))

typedef struct
{
Expand Down Expand Up @@ -521,7 +521,7 @@ static void emulate_server_send_channel_data(
static void save_dump(void* data, size_t size)
{
thread_param * p = global_thread_params;
if (p->in_streams_number < RAIL_ARRAY_SIZE(p->in_streams))
if (p->in_streams_number < ARRAY_SIZE(p->in_streams))
{
STREAM* s = &p->in_streams[p->in_streams_number];
s->data = malloc(size);
Expand Down Expand Up @@ -631,7 +631,7 @@ static void process_events_and_channel_data_from_plugin(thread_param* param)
counter);

// add to global event list
if (param->in_events_number < RAIL_ARRAY_SIZE(param->in_events))
if (param->in_events_number < ARRAY_SIZE(param->in_events))
{
save_event(event, &param->in_events[param->in_events_number]);
param->in_events_number++;
Expand Down
2 changes: 1 addition & 1 deletion cunit/test_rfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void test_rlgr(void)
{
int n;

n = rfx_rlgr_decode(RLGR3, y_data, sizeof(y_data), buffer, sizeof(buffer) / sizeof(unsigned int));
n = rfx_rlgr_decode(RLGR3, y_data, sizeof(y_data), buffer, ARRAY_SIZE(buffer));

//printf("RLGR decode %d bytes to %d values.", sizeof(y_data), n);
//dump_buffer(buffer, n);
Expand Down
3 changes: 2 additions & 1 deletion cunit/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <freerdp/utils/args.h>
#include <freerdp/utils/passphrase.h>
#include <freerdp/utils/signal.h>
#include <freerdp/utils/memory.h>

#include "test_utils.h"

Expand Down Expand Up @@ -142,7 +143,7 @@ void test_args(void)
"freerdp", "-a", "16", "-u", "testuser", "-d", "testdomain", "-g", "1280x960", "address2:3390"
};
char** argv = argv_c;
int argc = sizeof(argv_c) / sizeof(char*);
int argc = ARRAY_SIZE(argv_c);
int i;
int c;
rdpSettings* settings;
Expand Down
2 changes: 2 additions & 0 deletions include/freerdp/utils/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ FREERDP_API char* xstrdup(const char* str);

#define xnew(_type) (_type*)xzalloc(sizeof(_type))

#define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(*(_x)))

#endif /* __MEMORY_UTILS_H */
2 changes: 0 additions & 2 deletions include/freerdp/utils/rail.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <freerdp/utils/rect.h>
#include <freerdp/utils/stream.h>

#define RAIL_ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))

FREERDP_API void rail_unicode_string_alloc(UNICODE_STRING* unicode_string, uint16 cbString);
FREERDP_API void rail_unicode_string_free(UNICODE_STRING* unicode_string);
FREERDP_API void rail_read_unicode_string(STREAM* s, UNICODE_STRING* unicode_string);
Expand Down
8 changes: 4 additions & 4 deletions libfreerdp-auth/sspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ SECURITY_FUNCTION_TABLE* sspi_GetSecurityFunctionTableByName(const char* Name)
int index;
uint32 cPackages;

cPackages = sizeof(SEC_PKG_INFO_LIST) / sizeof(SEC_PKG_INFO*);
cPackages = ARRAY_SIZE(SEC_PKG_INFO_LIST);

for (index = 0; index < (int) cPackages; index++)
{
Expand Down Expand Up @@ -305,7 +305,7 @@ SECURITY_STATUS EnumerateSecurityPackages(uint32* pcPackages, SEC_PKG_INFO** ppP
uint32 cPackages;
SEC_PKG_INFO* pPackageInfo;

cPackages = sizeof(SEC_PKG_INFO_LIST) / sizeof(SEC_PKG_INFO*);
cPackages = ARRAY_SIZE(SEC_PKG_INFO_LIST);
size = sizeof(SEC_PKG_INFO) * cPackages;

pPackageInfo = (SEC_PKG_INFO*) sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
Expand All @@ -332,7 +332,7 @@ void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
uint32 cPackages;
SEC_PKG_INFO* pPackageInfo = (SEC_PKG_INFO*) contextBuffer;

cPackages = sizeof(SEC_PKG_INFO_LIST) / sizeof(SEC_PKG_INFO*);
cPackages = ARRAY_SIZE(SEC_PKG_INFO_LIST);

for (index = 0; index < (int) cPackages; index++)
{
Expand Down Expand Up @@ -361,7 +361,7 @@ SECURITY_STATUS QuerySecurityPackageInfo(char* pszPackageName, SEC_PKG_INFO** pp
uint32 cPackages;
SEC_PKG_INFO* pPackageInfo;

cPackages = sizeof(SEC_PKG_INFO_LIST) / sizeof(SEC_PKG_INFO*);
cPackages = ARRAY_SIZE(SEC_PKG_INFO_LIST);

for (index = 0; index < (int) cPackages; index++)
{
Expand Down
12 changes: 5 additions & 7 deletions libfreerdp-core/certificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

#include <freerdp/utils/file.h>

static const char certificate_store_dir[] = "certs";
static const char certificate_known_hosts_file[] = "known_hosts";

#include "certificate.h"

/**
Expand Down Expand Up @@ -448,15 +445,16 @@ boolean certificate_read_server_certificate(rdpCertificate* certificate, uint8*
STREAM* s;
uint32 dwVersion;

s = stream_new(0);
stream_attach(s, server_cert, length);

printf("length %d\n", length);
if (length < 1)
{
printf("null server certificate\n");
DEBUG_CERTIFICATE("null server certificate\n");
return false;
}

s = stream_new(0);
stream_attach(s, server_cert, length);

stream_read_uint32(s, dwVersion); /* dwVersion (4 bytes) */

switch (dwVersion & CERT_CHAIN_VERSION_MASK)
Expand Down
6 changes: 3 additions & 3 deletions libfreerdp-core/orders.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const char* const SECONDARY_DRAWING_ORDER_STRINGS[] =
"Cache Bitmap V3"
};

#define SECONDARY_DRAWING_ORDER_COUNT (sizeof(SECONDARY_DRAWING_ORDER_STRINGS) / sizeof(SECONDARY_DRAWING_ORDER_STRINGS[0]))
#define SECONDARY_DRAWING_ORDER_COUNT (ARRAY_SIZE(SECONDARY_DRAWING_ORDER_STRINGS))

static const char* const ALTSEC_DRAWING_ORDER_STRINGS[] =
{
Expand All @@ -88,7 +88,7 @@ static const char* const ALTSEC_DRAWING_ORDER_STRINGS[] =
"Frame Marker"
};

#define ALTSEC_DRAWING_ORDER_COUNT (sizeof(ALTSEC_DRAWING_ORDER_STRINGS) / sizeof(ALTSEC_DRAWING_ORDER_STRINGS[0]))
#define ALTSEC_DRAWING_ORDER_COUNT (ARRAY_SIZE(ALTSEC_DRAWING_ORDER_STRINGS))

#endif /* WITH_DEBUG_ORDERS */

Expand Down Expand Up @@ -121,7 +121,7 @@ static const uint8 PRIMARY_DRAWING_ORDER_FIELD_BYTES[] =
GLYPH_INDEX_ORDER_FIELD_BYTES
};

#define PRIMARY_DRAWING_ORDER_COUNT (sizeof(PRIMARY_DRAWING_ORDER_FIELD_BYTES) / sizeof(PRIMARY_DRAWING_ORDER_FIELD_BYTES[0]))
#define PRIMARY_DRAWING_ORDER_COUNT (ARRAY_SIZE(PRIMARY_DRAWING_ORDER_FIELD_BYTES))

static const uint8 CBR2_BPP[] =
{
Expand Down
25 changes: 14 additions & 11 deletions libfreerdp-core/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@

#include <freerdp/crypto/per.h>

#ifdef WITH_DEBUG_RDP
static const char* const DATA_PDU_TYPE_STRINGS[] =
{
"", "", /* 0x00 - 0x01 */
"?", "?", /* 0x00 - 0x01 */
"Update", /* 0x02 */
"", "", "", "", "", "", "", "", /* 0x03 - 0x0A */
"", "", "", "", "", "", "", "", "", /* 0x0B - 0x13 */
"?", "?", "?", "?", "?", "?", "?", "?", /* 0x03 - 0x0A */
"?", "?", "?", "?", "?", "?", "?", "?", "?", /* 0x0B - 0x13 */
"Control", /* 0x14 */
"", "", "", "", "", "", /* 0x15 - 0x1A */
"?", "?", "?", "?", "?", "?", /* 0x15 - 0x1A */
"Pointer", /* 0x1B */
"Input", /* 0x1C */
"", "", /* 0x1D - 0x1E */
"?", "?", /* 0x1D - 0x1E */
"Synchronize", /* 0x1F */
"", /* 0x20 */
"?", /* 0x20 */
"Refresh Rect", /* 0x21 */
"Play Sound", /* 0x22 */
"Suppress Output", /* 0x23 */
Expand All @@ -46,7 +47,7 @@ static const char* const DATA_PDU_TYPE_STRINGS[] =
"Font List", /* 0x27 */
"Font Map", /* 0x28 */
"Set Keyboard Indicators", /* 0x29 */
"", /* 0x2A */
"?", /* 0x2A */
"Bitmap Cache Persistent List", /* 0x2B */
"Bitmap Cache Error", /* 0x2C */
"Set Keyboard IME Status", /* 0x2D */
Expand All @@ -55,12 +56,13 @@ static const char* const DATA_PDU_TYPE_STRINGS[] =
"Draw Nine Grid Error", /* 0x30 */
"Draw GDI+ Error", /* 0x31 */
"ARC Status", /* 0x32 */
"", "", "", /* 0x33 - 0x35 */
"?", "?", "?", /* 0x33 - 0x35 */
"Status Info", /* 0x36 */
"Monitor Layout" /* 0x37 */
"", "", "", /* 0x38 - 0x40 */
"", "", "", "", "", "" /* 0x41 - 0x46 */
"?", "?", "?", /* 0x38 - 0x40 */
"?", "?", "?", "?", "?", "?" /* 0x41 - 0x46 */
};
#endif

/**
* Read RDP Security Header.\n
Expand Down Expand Up @@ -484,7 +486,8 @@ boolean rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s)

#ifdef WITH_DEBUG_RDP
if (type != DATA_PDU_TYPE_UPDATE)
printf("recv %s Data PDU (0x%02X), length:%d\n", DATA_PDU_TYPE_STRINGS[type], type, length);
printf("recv %s Data PDU (0x%02X), length:%d\n",
type < ARRAY_SIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
#endif

switch (type)
Expand Down
12 changes: 6 additions & 6 deletions libfreerdp-locale/keyboard_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(uint32 types)

if ((types & RDP_KEYBOARD_LAYOUT_TYPE_STANDARD) != 0)
{
length = sizeof(RDP_KEYBOARD_LAYOUT_TABLE) / sizeof(RDP_KEYBOARD_LAYOUT);
length = ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) xrealloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -1012,7 +1012,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(uint32 types)
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_VARIANT) != 0)
{
length = sizeof(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE) / sizeof(RDP_KEYBOARD_LAYOUT_VARIANT);
length = ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) xrealloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -1023,7 +1023,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(uint32 types)
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_IME) != 0)
{
length = sizeof(RDP_KEYBOARD_IME_TABLE) / sizeof(RDP_KEYBOARD_IME);
length = ARRAY_SIZE(RDP_KEYBOARD_IME_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) realloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -1042,19 +1042,19 @@ const char* freerdp_keyboard_get_layout_name_from_id(uint32 keyboardLayoutID)
{
int i;

for (i = 0; i < sizeof(RDP_KEYBOARD_LAYOUT_TABLE) / sizeof(RDP_KEYBOARD_LAYOUT); i++)
for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
{
if (RDP_KEYBOARD_LAYOUT_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_LAYOUT_TABLE[i].name;
}

for (i = 0; i < sizeof(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE) / sizeof(RDP_KEYBOARD_LAYOUT_VARIANT); i++)
for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE); i++)
{
if (RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name;
}

for (i = 0; i < sizeof(RDP_KEYBOARD_IME_TABLE) / sizeof(RDP_KEYBOARD_IME); i++)
for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_IME_TABLE); i++)
{
if (RDP_KEYBOARD_IME_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_IME_TABLE[i].name;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp-locale/keyboard_sun.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ uint32 freerdp_detect_keyboard_type_and_layout_solaris(char* xkbfile, int length
}
pclose(kbd);

for (i = 0; i < sizeof(SOLARIS_KEYBOARD_TABLE) / sizeof(SOLARIS_KEYBOARD); i++)
for (i = 0; i < ARRAY_SIZE(SOLARIS_KEYBOARD_TABLE); i++)
{
if (SOLARIS_KEYBOARD_TABLE[i].type == type)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp-locale/keyboard_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ uint32 find_keyboard_layout_in_xorg_rules(char* layout, char* variant)

DEBUG_KBD("xkbLayout: %s\txkbVariant: %s", layout, variant);

for (i = 0; i < sizeof(xkbLayouts) / sizeof(XKB_LAYOUT); i++)
for (i = 0; i < ARRAY_SIZE(xkbLayouts); i++)
{
if (strcmp(xkbLayouts[i].layout, layout) == 0)
{
Expand Down
7 changes: 4 additions & 3 deletions libfreerdp-locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string.h>
#include "liblocale.h"

#include <freerdp/utils/memory.h>
#include <freerdp/locale/locale.h>

struct _SYSTEM_LOCALE
Expand Down Expand Up @@ -673,7 +674,7 @@ SYSTEM_LOCALE* freerdp_detect_system_locale()

freerdp_get_system_language_and_country_codes(language, country);

for (i = 0; i < sizeof(SYSTEM_LOCALE_TABLE) / sizeof(SYSTEM_LOCALE); i++)
for (i = 0; i < ARRAY_SIZE(SYSTEM_LOCALE_TABLE); i++)
{
if ((strcmp(language, SYSTEM_LOCALE_TABLE[i].language) == 0) && (strcmp(country, SYSTEM_LOCALE_TABLE[i].country) == 0))
{
Expand Down Expand Up @@ -701,7 +702,7 @@ const char* freerdp_get_system_locale_name_from_id(uint32 localeId)
{
int index;

for (index = 0; index < sizeof(LOCALE_NAME_TABLE) / sizeof(LOCALE_NAME); index++)
for (index = 0; index < ARRAY_SIZE(LOCALE_NAME_TABLE); index++)
{
if (localeId == LOCALE_NAME_TABLE[index].localeId)
return LOCALE_NAME_TABLE[index].name;
Expand Down Expand Up @@ -729,7 +730,7 @@ uint32 freerdp_detect_keyboard_layout_from_system_locale()

DEBUG_KBD("Found locale : %s_%s", locale->language, locale->country);

for (i = 0; i < sizeof(LOCALE_KEYBOARD_LAYOUTS_TABLE) / sizeof(LOCALE_KEYBOARD_LAYOUTS); i++)
for (i = 0; i < ARRAY_SIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
{
if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].locale == locale->code)
{
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp-locale/timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,11 +1576,11 @@ TIME_ZONE_ENTRY* freerdp_detect_windows_time_zone(uint32 bias)
if (tzid == NULL)
return NULL;

for (i = 0; i < sizeof(TimeZoneTable) / sizeof(TIME_ZONE_ENTRY); i++)
for (i = 0; i < ARRAY_SIZE(TimeZoneTable); i++)
{
if (bias == TimeZoneTable[i].Bias)
{
for (j = 0; j < sizeof(WindowsTimeZoneIdTable) / sizeof(WINDOWS_TZID_ENTRY); j++)
for (j = 0; j < ARRAY_SIZE(WindowsTimeZoneIdTable); j++)
{
if (strcmp(TimeZoneTable[i].Id, WindowsTimeZoneIdTable[j].windows) != 0)
continue;
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp-rail/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void print_window_styles(uint32 style)
int i;

printf("Window Styles:\n{\n");
for (i = 0; i < sizeof(WINDOW_STYLES) / sizeof(WINDOW_STYLE); i++)
for (i = 0; i < ARRAY_SIZE(WINDOW_STYLES); i++)
{
if (style & WINDOW_STYLES[i].style)
{
Expand All @@ -117,7 +117,7 @@ void print_extended_window_styles(uint32 style)
int i;

printf("Extended Window Styles:\n{\n");
for (i = 0; i < sizeof(EXTENDED_WINDOW_STYLES) / sizeof(WINDOW_STYLE); i++)
for (i = 0; i < ARRAY_SIZE(EXTENDED_WINDOW_STYLES); i++)
{
if (style & EXTENDED_WINDOW_STYLES[i].style)
{
Expand Down
Loading

0 comments on commit 54b26c4

Please sign in to comment.