Commit 34a0d032 authored by Niels Möller's avatar Niels Möller
Browse files

Ignore zeros in the lists passed to %A.

Rev: src/format.c:1.15
Rev: src/format.h:1.12
parent b5fc9824
...@@ -148,16 +148,20 @@ UINT32 ssh_vformat_length(char *f, va_list args) ...@@ -148,16 +148,20 @@ UINT32 ssh_vformat_length(char *f, va_list args)
case 'A': case 'A':
{ {
int *atom = va_arg(args, int *); int *atom = va_arg(args, int *);
int i; int n;
if (atom[0]) for(n = 0; *atom >= 0; atom++)
{ /* Non empty */ {
for(i = 0; atom[i] > 0; i++) if (*atom)
length += get_atom_length(atom[i]) + 1; {
n++;
/* One ','-character less than the number of atoms */ length += get_atom_length(*atom);
length--; }
} }
if (n)
/* One ','-character less than the number of atoms */
length += (n-1);
if (!literal) if (!literal)
length += 4; length += 4;
f++; f++;
...@@ -333,26 +337,28 @@ UINT32 ssh_vformat(char *f, UINT8 *buffer, va_list args) ...@@ -333,26 +337,28 @@ UINT32 ssh_vformat(char *f, UINT8 *buffer, va_list args)
{ {
int *atom = va_arg(args, int *); int *atom = va_arg(args, int *);
UINT8 *start = buffer; /* Where to store the length */ UINT8 *start = buffer; /* Where to store the length */
int i; int n;
if (!literal) if (!literal)
buffer += 4; buffer += 4;
if (atom[0] > 0) for(n = 0; *atom >= 0; atom++)
{ {
UINT32 length = get_atom_length(atom[0]); if (*atom)
memcpy(buffer, get_atom_name(atom[0]), length);
buffer += length;
for (i = 1; atom[i] > 0; i++)
{ {
*buffer++ = ','; UINT32 length = get_atom_length(*atom);
length = get_atom_length(atom[i]);
memcpy(buffer, get_atom_name(atom[i]), length); if (n)
/* Not the first atom */
*buffer++ = ',';
memcpy(buffer, get_atom_name(atom[0]), length);
buffer += length; buffer += length;
n++;
} }
} }
if (!literal) if (!literal)
{ {
UINT32 total = buffer - start - 4; UINT32 total = buffer - start - 4;
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
* *
* %A Insert a string containing a list of atoms. The corresponding * %A Insert a string containing a list of atoms. The corresponding
* argument sublist should be a int* pointing to a list of atoms, * argument sublist should be a int* pointing to a list of atoms,
* terminated with -1. * terminated with -1. Zero elements are allowed and ignored.
* *
* %X Insert a string containing a list of atoms. The corresponding * %X Insert a string containing a list of atoms. The corresponding
* argument sublist should be terminated with a zero. (Not used) * argument sublist should be terminated with a zero. (Not used)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment