Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
0593b33b
Commit
0593b33b
authored
Aug 07, 2014
by
Thomas Jahns
🤸
Browse files
Fix pack size computations.
parent
2f2eacf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/institution.c
View file @
0593b33b
...
...
@@ -3,6 +3,7 @@
#endif
#include
<assert.h>
#include
<limits.h>
#include
"dmemory.h"
#include
"cdi.h"
...
...
@@ -307,10 +308,13 @@ enum {
static
int
instituteGetPackSize
(
institute_t
*
ip
,
void
*
context
)
{
int
txsize
=
serializeGetSize
(
institute_nints
,
DATATYPE_INT
,
context
)
+
serializeGetSize
(
strlen
(
ip
->
name
)
+
1
,
DATATYPE_TXT
,
context
)
+
serializeGetSize
(
strlen
(
ip
->
longname
)
+
1
,
DATATYPE_TXT
,
context
);
return
txsize
;
size_t
namelen
=
strlen
(
ip
->
name
),
longnamelen
=
strlen
(
ip
->
longname
);
xassert
(
namelen
<
INT_MAX
&&
longnamelen
<
INT_MAX
);
size_t
txsize
=
(
size_t
)
serializeGetSize
(
institute_nints
,
DATATYPE_INT
,
context
)
+
(
size_t
)
serializeGetSize
((
int
)
namelen
+
1
,
DATATYPE_TXT
,
context
)
+
(
size_t
)
serializeGetSize
((
int
)
longnamelen
+
1
,
DATATYPE_TXT
,
context
);
xassert
(
txsize
<=
INT_MAX
);
return
(
int
)
txsize
;
}
static
void
institutePackP
(
void
*
instituteptr
,
void
*
buf
,
int
size
,
int
*
position
,
void
*
context
)
...
...
@@ -334,7 +338,7 @@ int instituteUnpack(void *buf, int size, int *position, int originNamespace,
int
instituteID
;
char
*
name
,
*
longname
;
serializeUnpack
(
buf
,
size
,
position
,
tempbuf
,
institute_nints
,
DATATYPE_INT
,
context
);
name
=
(
char
*
)
xmalloc
(
tempbuf
[
3
]
+
tempbuf
[
4
]);
name
=
(
char
*
)
xmalloc
(
(
size_t
)
tempbuf
[
3
]
+
(
size_t
)
tempbuf
[
4
]);
longname
=
name
+
tempbuf
[
3
];
serializeUnpack
(
buf
,
size
,
position
,
name
,
tempbuf
[
3
],
DATATYPE_TXT
,
context
);
serializeUnpack
(
buf
,
size
,
position
,
longname
,
tempbuf
[
4
],
DATATYPE_TXT
,
context
);
...
...
src/model.c
View file @
0593b33b
...
...
@@ -2,6 +2,8 @@
# include "config.h"
#endif
#include
<limits.h>
#include
"dmemory.h"
#include
"cdi.h"
#include
"cdi_int.h"
...
...
@@ -293,10 +295,11 @@ enum {
static
int
modelGetSizeP
(
void
*
modelptr
,
void
*
context
)
{
model_t
*
p
=
(
model_t
*
)
modelptr
;
int
txsize
=
serializeGetSize
(
model_nints
,
DATATYPE_INT
,
context
)
+
serializeGetSize
(
p
->
name
?
strlen
(
p
->
name
)
+
1
:
0
,
DATATYPE_TXT
,
context
);
return
txsize
;
model_t
*
p
=
(
model_t
*
)
modelptr
;
size_t
txsize
=
(
size_t
)
serializeGetSize
(
model_nints
,
DATATYPE_INT
,
context
)
+
(
size_t
)
serializeGetSize
(
p
->
name
?
(
int
)
strlen
(
p
->
name
)
+
1
:
0
,
DATATYPE_TXT
,
context
);
xassert
(
txsize
<=
INT_MAX
);
return
(
int
)
txsize
;
}
...
...
@@ -322,8 +325,9 @@ modelUnpack(void *buf, int size, int *position, int originNamespace, void *conte
serializeUnpack
(
buf
,
size
,
position
,
tempbuf
,
model_nints
,
DATATYPE_INT
,
context
);
if
(
tempbuf
[
3
]
!=
0
)
{
name
=
(
char
*
)
xmalloc
(
tempbuf
[
3
]);
serializeUnpack
(
buf
,
size
,
position
,
name
,
tempbuf
[
3
],
DATATYPE_TXT
,
context
);
name
=
(
char
*
)
xmalloc
((
size_t
)
tempbuf
[
3
]);
serializeUnpack
(
buf
,
size
,
position
,
name
,
tempbuf
[
3
],
DATATYPE_TXT
,
context
);
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment