aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-11-14 10:19:31 -0600
committerfiaxh <git@lightrise.org>2024-11-14 10:20:12 -0600
commit909f569318835d11703c49fba7dbe49996759f38 (patch)
tree24616308c4f6d7a8fa34a2c08de29fda317ba726 /xmpp-vala/src/core
parenta6554e81c5cd766b0936e4dd3c46cd6131a3cc8b (diff)
downloaddino-909f569318835d11703c49fba7dbe49996759f38.tar.gz
dino-909f569318835d11703c49fba7dbe49996759f38.zip
xmpp-vala: StanzaNode.get_attribute_int: Return default value if not parsable as int
Diffstat (limited to 'xmpp-vala/src/core')
-rw-r--r--xmpp-vala/src/core/stanza_node.vala26
1 files changed, 20 insertions, 6 deletions
diff --git a/xmpp-vala/src/core/stanza_node.vala b/xmpp-vala/src/core/stanza_node.vala
index 44a70d8d..54c14956 100644
--- a/xmpp-vala/src/core/stanza_node.vala
+++ b/xmpp-vala/src/core/stanza_node.vala
@@ -98,15 +98,29 @@ public class StanzaNode : StanzaEntry {
}
public int get_attribute_int(string name, int def = -1, string? ns_uri = null) {
- string? res = get_attribute(name, ns_uri);
- if (res == null) return def;
- return int.parse((!)res);
+ string? attribute_str = get_attribute(name, ns_uri);
+ if (attribute_str == null) return def;
+
+ int res = def;
+ bool parse_success = int.try_parse(attribute_str, out res);
+ if (!parse_success) {
+ info("Could not parse int attribute %s: %s", name, attribute_str);
+ return def;
+ }
+ return res;
}
public uint get_attribute_uint(string name, uint def = 0, string? ns_uri = null) {
- string? res = get_attribute(name, ns_uri);
- if (res == null) return def;
- return (uint) long.parse((!)res);
+ string? attribute_str = get_attribute(name, ns_uri);
+ if (attribute_str == null) return def;
+
+ uint res = def;
+ bool parse_success = uint.try_parse(attribute_str, out res);
+ if (!parse_success) {
+ info("Could not parse uint attribute %s: %s", name, attribute_str);
+ return def;
+ }
+ return res;
}
public bool get_attribute_bool(string name, bool def = false, string? ns_uri = null) {