Fix a few signed vs. unsigned and differently-sized integer problems

Most notably, utils_get_line_endings() and document_open_file_list()
don't support -1 as the size anymore.  If the size should be computed
from null-terminated data, the caller code must take care of doing so.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5855 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Colomban Wendling 2011-06-17 22:52:17 +00:00
parent 254007f22c
commit 3bd6a01525
9 changed files with 32 additions and 30 deletions

View File

@ -1,3 +1,11 @@
2011-06-18 Colomban Wendling <colomban(at)geany(dot)org>
* src/document.c, src/document.h, src/editor.c:
Remove support of size being -1 in document_open_file_list().
* src/utils.c src/utils.h:
Remove support of size being -1 in utils_get_line_endings().
2011-06-16 Colomban Wendling <colomban(at)geany(dot)org>
* src/document.c, src/main.c, src/ui_utils.c, src/utils.c:

View File

@ -374,7 +374,7 @@ static GtkWidget *cc_option_label_new(const gchar *text)
/* Attaches a new section label at the specified table row, optionally
* padded at the top, and returns the new label. */
static GtkWidget *cc_table_attach_section_label(GtkWidget *table, const gchar *text,
gint row, gboolean top_padding)
guint row, gboolean top_padding)
{
gchar *markup;
GtkWidget *label, *align;
@ -399,7 +399,7 @@ static GtkWidget *cc_table_attach_section_label(GtkWidget *table, const gchar *t
/* Attach a new option label at the specified table row and returns
* the label */
static GtkWidget *cc_table_attach_option_label(GtkWidget *table, const gchar *text, gint row)
static GtkWidget *cc_table_attach_option_label(GtkWidget *table, const gchar *text, guint row)
{
GtkWidget *opt_label = cc_option_label_new(text);
gtk_table_attach(GTK_TABLE(table), opt_label,
@ -412,7 +412,7 @@ static GtkWidget *cc_table_attach_option_label(GtkWidget *table, const gchar *te
* The label associated with the widget is set as data on the entry
* with the "label" key, if access to it is needed later. The entry
* widget is returned. */
static GtkWidget *cc_table_attach_option_entry(GtkWidget *table, const gchar *text, gint row)
static GtkWidget *cc_table_attach_option_entry(GtkWidget *table, const gchar *text, guint row)
{
GtkWidget *label;
GtkWidget *entry;
@ -430,7 +430,7 @@ static void show_dialog_create_class(gint type)
CreateClassDialog *cc_dlg;
GtkWidget *main_box, *table, *label, *hdr_hbox;
GtkWidget *opt_table, *align;
gint row;
guint row;
cc_dlg = g_new0(CreateClassDialog, 1);
cc_dlg->class_type = type;

View File

@ -649,10 +649,10 @@ static void replace_special_character(void)
if (doc != NULL && sci_has_selection(doc->editor->sci))
{
guint selection_len;
gsize selection_len;
gchar *selection;
GString *replacement = g_string_new(NULL);
guint i;
gsize i;
gchar *new;
const gchar *entity = NULL;
gchar buf[7];
@ -664,7 +664,7 @@ static void replace_special_character(void)
for (i = 0; i < selection_len; i++)
{
len = g_unichar_to_utf8(g_utf8_get_char(selection + i), buf);
i = len - 1 + i;
i = (guint)len - 1 + i;
buf[len] = '\0';
entity = get_entity(buf);

View File

@ -221,7 +221,7 @@ static GtkTreeStore *create_encoding_combo_store(GtkTreeIter *iter_detect)
iter_utf8, iter_middleeast;
GtkTreeIter *iter_parent;
gchar *encoding_string;
guint i;
gint i;
store = gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING);

View File

@ -307,7 +307,7 @@ gchar *document_get_basename_for_display(GeanyDocument *doc, gint length)
length = 30;
base_name = g_path_get_basename(DOC_FILENAME(doc));
short_name = utils_str_middle_truncate(base_name, length);
short_name = utils_str_middle_truncate(base_name, (guint)length);
g_free(base_name);
@ -926,7 +926,7 @@ static gboolean detect_tabs_and_spaces(GeanyEditor *editor)
ScintillaObject *sci = editor->sci;
gsize count = 0;
struct Sci_TextToFind ttf;
gchar *soft_tab = g_strnfill(iprefs->width, ' ');
gchar *soft_tab = g_strnfill((gsize)iprefs->width, ' ');
gchar *regex = g_strconcat("^\t+", soft_tab, "[^ ]", NULL);
g_free(soft_tab);
@ -955,7 +955,7 @@ static GeanyIndentType detect_indent_type(GeanyEditor *editor)
{
const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
ScintillaObject *sci = editor->sci;
guint line, line_count;
gint line, line_count;
gsize tabs = 0, spaces = 0;
if (detect_tabs_and_spaces(editor))
@ -997,7 +997,7 @@ static gint detect_indent_width(GeanyEditor *editor, GeanyIndentType type)
{
const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
ScintillaObject *sci = editor->sci;
guint line, line_count;
gint line, line_count;
gint widths[7] = { 0 }; /* width can be from 2 to 8 */
gint count, width, i;
@ -1282,18 +1282,15 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename
/* Takes a new line separated list of filename URIs and opens each file.
* length is the length of the string or -1 if it should be detected */
void document_open_file_list(const gchar *data, gssize length)
* length is the length of the string */
void document_open_file_list(const gchar *data, gsize length)
{
gint i;
guint i;
gchar *filename;
gchar **list;
g_return_if_fail(data != NULL);
if (length < 0)
length = strlen(data);
list = g_strsplit(data, utils_get_eol_char(utils_get_line_endings(data, length)), 0);
for (i = 0; list[i] != NULL; i++)

View File

@ -209,7 +209,7 @@ GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename
GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos,
gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
void document_open_file_list(const gchar *data, gssize length);
void document_open_file_list(const gchar *data, gsize length);
void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
const gchar *forced_enc);

View File

@ -1102,7 +1102,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi
case SCN_URIDROPPED:
if (nt->text != NULL)
{
document_open_file_list(nt->text, -1);
document_open_file_list(nt->text, strlen(nt->text));
}
break;

View File

@ -120,15 +120,12 @@ void utils_open_browser(const gchar *uri)
/* taken from anjuta, to determine the EOL mode of the file */
gint utils_get_line_endings(const gchar* buffer, glong size)
gint utils_get_line_endings(const gchar* buffer, gsize size)
{
gint i;
gsize i;
guint cr, lf, crlf, max_mode;
gint mode;
if (size == -1)
size = strlen(buffer);
cr = lf = crlf = 0;
for (i = 0; i < size ; i++)
@ -247,7 +244,7 @@ gint utils_write_file(const gchar *filename, const gchar *text)
else
{
FILE *fp;
gint bytes_written, len;
gsize bytes_written, len;
gboolean fail = FALSE;
if (filename == NULL)
@ -266,7 +263,7 @@ gint utils_write_file(const gchar *filename, const gchar *text)
{
fail = TRUE;
geany_debug(
"utils_write_file(): written only %d bytes, had to write %d bytes to %s",
"utils_write_file(): written only %"G_GSIZE_FORMAT" bytes, had to write %"G_GSIZE_FORMAT" bytes to %s",
bytes_written, len, filename);
}
if (fclose(fp) != 0)
@ -291,7 +288,7 @@ gint utils_write_file(const gchar *filename, const gchar *text)
gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
{
const gchar *cur, *begin;
gint len;
gsize len;
cur = utils_find_open_xml_tag_pos(sel, size);
if (cur == NULL)
@ -302,7 +299,7 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
while (strchr(":_-.", *cur) || isalnum(*cur))
cur++;
len = cur - begin;
len = (gsize)(cur - begin);
return len ? g_strndup(begin, len) : NULL;
}

View File

@ -132,7 +132,7 @@
void utils_open_browser(const gchar *uri);
gint utils_get_line_endings(const gchar* buffer, glong size);
gint utils_get_line_endings(const gchar* buffer, gsize size);
gboolean utils_isbrace(gchar c, gboolean include_angles);