summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-07-04 12:39:01 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-07-04 12:39:01 (GMT)
commitade3ee4fd3b78e96deb08210838643969f2f6699 (patch)
tree09003a6f4ac00c09560de9ea9a91c125a7b14f68 /src/format
parenta0463dfa8fe232d01ea925668f393d7507fa787b (diff)
Updated the API for building symbol labels.
Diffstat (limited to 'src/format')
-rw-r--r--src/format/format.c4
-rw-r--r--src/format/symbol-int.h2
-rw-r--r--src/format/symbol.c39
-rw-r--r--src/format/symbol.h2
4 files changed, 35 insertions, 12 deletions
diff --git a/src/format/format.c b/src/format/format.c
index fa11663..439bd3e 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -961,7 +961,7 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label,
{
bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
- const char *cur_lbl; /* Etiquette courante */
+ char *cur_lbl; /* Etiquette courante */
result = false;
@@ -981,6 +981,8 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label,
}
+ free(cur_lbl);
+
}
g_binary_format_unlock_symbols_rd(format);
diff --git a/src/format/symbol-int.h b/src/format/symbol-int.h
index 780a510..1b8672d 100644
--- a/src/format/symbol-int.h
+++ b/src/format/symbol-int.h
@@ -30,7 +30,7 @@
/* Fournit une étiquette pour viser un symbole. */
-typedef const char * (* get_symbol_label_fc) (GBinSymbol *);
+typedef char * (* get_symbol_label_fc) (const GBinSymbol *);
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 13ce23d..3f8e808 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -25,6 +25,7 @@
#include <assert.h>
+#include <malloc.h>
#include <string.h>
@@ -396,12 +397,12 @@ SymbolStatus g_binary_symbol_get_status(const GBinSymbol *symbol)
* *
******************************************************************************/
-const char *g_binary_symbol_get_label(const GBinSymbol *symbol)
+char *g_binary_symbol_get_label(const GBinSymbol *symbol)
{
- const char *result; /* Etiquette à retourner */
+ char *result; /* Etiquette à retourner */
if (symbol->alt != NULL)
- result = symbol->alt;
+ result = strdup(symbol->alt);
else if (G_BIN_SYMBOL_GET_CLASS(symbol)->get_label != NULL)
result = G_BIN_SYMBOL_GET_CLASS(symbol)->get_label(symbol);
@@ -461,11 +462,18 @@ void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)
GLineGenerator *g_binary_symbol_produce_label(GBinSymbol *symbol)
{
GLineGenerator *result; /* Instance à retourner */
- const char *label; /* Etiquette à insérer */
+ char *label; /* Etiquette à insérer */
label = g_binary_symbol_get_label(symbol);
- result = (label != NULL ? G_LINE_GENERATOR(symbol) : NULL);
+ if (label == NULL)
+ result = NULL;
+
+ else
+ {
+ result = G_LINE_GENERATOR(symbol);
+ free(label);
+ }
return result;
@@ -590,14 +598,27 @@ static BufferLineFlags g_binary_symbol_get_flags(const GBinSymbol *symbol, size_
static void g_binary_symbol_print(GBinSymbol *symbol, GBufferLine *line, size_t index, size_t repeat, const GBinContent *content)
{
- const char *label; /* Etiquette à insérer */
+ char *label; /* Etiquette à insérer */
g_buffer_line_fill_vmpa(line, get_mrange_addr(&symbol->range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED);
label = g_binary_symbol_get_label(symbol);
- g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, SL(label), RTT_LABEL, NULL);
- g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ":", 1, RTT_PUNCT, NULL);
+ /**
+ * Normalement, l'étiquette n'est pas vide car le générateur provient de
+ * g_binary_symbol_produce_label(), qui filtre.
+ *
+ * Mais le symbole a pu être manipulé entre temps, donc on évite un assert().
+ */
+
+ if (label != NULL)
+ {
+ g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD);
+ g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, SL(label), RTT_LABEL, NULL);
+ g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ":", 1, RTT_PUNCT, NULL);
+
+ free(label);
+
+ }
}
diff --git a/src/format/symbol.h b/src/format/symbol.h
index 881c2f2..13747d4 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -109,7 +109,7 @@ void g_binary_symbol_set_status(GBinSymbol *, SymbolStatus);
SymbolStatus g_binary_symbol_get_status(const GBinSymbol *);
/* Fournit une étiquette pour viser un symbole. */
-const char *g_binary_symbol_get_label(const GBinSymbol *);
+char *g_binary_symbol_get_label(const GBinSymbol *);
/* Définit un autre nom pour le symbole. */
void g_binary_symbol_set_alt_label(GBinSymbol *, const char *);