[libvirt] [PATCH 02/10] Replace sscanf in nwfilter rule parsing

Stefan Berger stefanb at us.ibm.com
Tue Mar 30 22:04:28 UTC 2010


libvir-list-bounces at redhat.com wrote on 03/30/2010 12:20:26 PM:

> 
> ---
>  src/conf/nwfilter_conf.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
> index 668918d..24b79a7 100644
> --- a/src/conf/nwfilter_conf.c
> +++ b/src/conf/nwfilter_conf.c
> @@ -1226,7 +1226,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn
> ATTRIBUTE_UNUSED,
> 
>                          case DATATYPE_UINT8:
>                              storage_ptr = &item->u.u8;
> -                            if (sscanf(prop, "%d", &int_val) == 1) {
> +                            if (virStrToLong_i(prop, NULL, 10, 
> &int_val) >= 0) {
>                                  if (int_val >= 0 && int_val <= 0xff) {
>                                      if (!validator)
>                                          *(uint8_t *)storage_ptr = 
int_val;
> @@ -1240,7 +1240,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn
> ATTRIBUTE_UNUSED,
> 
>                          case DATATYPE_UINT16:
>                              storage_ptr = &item->u.u16;
> -                            if (sscanf(prop, "%d", &int_val) == 1) {
> +                            if (virStrToLong_i(prop, NULL, 10, 
> &int_val) >= 0) {
>                                  if (int_val >= 0 && int_val <= 0xffff) 
{
>                                      if (!validator)
>                                          *(uint16_t *)storage_ptr = 
int_val;
> @@ -1264,7 +1264,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn
> ATTRIBUTE_UNUSED,
>                          case DATATYPE_IPMASK:
>                              storage_ptr = &item->u.u8;
>                              if (!virNWIPv4AddressParser(prop, &ipaddr)) 
{
> -                                if (sscanf(prop, "%d", &int_val) == 1) 
{
> +                                if (virStrToLong_i(prop, NULL, 10, 
> &int_val) >= 0) {
>                                      if (int_val >= 0 && int_val <= 32) 
{
>                                          if (!validator)
>                                              *(uint8_t *)storage_ptr =
> @@ -1319,7 +1319,7 @@ virNWFilterRuleDetailsParse(virConnectPtr conn
> ATTRIBUTE_UNUSED,
>                          case DATATYPE_IPV6MASK:
>                              storage_ptr = &item->u.u8;
>                              if (!virNWIPv6AddressParser(prop, &ipaddr)) 
{
> -                                if (sscanf(prop, "%d", &int_val) == 1) 
{
> +                                if (virStrToLong_i(prop, NULL, 10, 
> &int_val) >= 0) {
>                                      if (int_val >= 0 && int_val <= 128) 
{
>                                          if (!validator)
>                                              *(uint8_t *)storage_ptr =
> @@ -1607,7 +1607,7 @@ virNWFilterRuleParse(virConnectPtr conn,
>      ret->priority = MAX_RULE_PRIORITY / 2;
> 
>      if (prio) {
> -        if (sscanf(prio, "%d", (int *)&priority) == 1) {
> +        if (virStrToLong_i(prio, NULL, 10, (int *)&priority) >= 0) {
>              if ((int)priority >= 0 && priority <= MAX_RULE_PRIORITY)
>                  ret->priority = priority;
>          }
> -- 

Looks good to me.


   Stefan


> 1.6.3.3
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100330/baf34b23/attachment-0001.htm>


More information about the libvir-list mailing list