Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Hoffmann
nettle
Commits
c1581854
Commit
c1581854
authored
Oct 1, 2002
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
* examples/io.c (read_file): Bug fix, used to overwrite pointer.
Rev: src/nettle/examples/io.c:1.2
parent
577e1b4f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/io.c
+11
-8
11 additions, 8 deletions
examples/io.c
with
11 additions
and
8 deletions
examples/io.c
+
11
−
8
View file @
c1581854
...
@@ -52,17 +52,18 @@ werror(const char *format, ...)
...
@@ -52,17 +52,18 @@ werror(const char *format, ...)
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
unsigned
unsigned
read_file
(
const
char
*
name
,
unsigned
max_size
,
char
**
buffer
)
read_file
(
const
char
*
name
,
unsigned
max_size
,
char
**
contents
)
{
{
unsigned
size
;
unsigned
size
;
unsigned
done
;
unsigned
done
;
char
*
buffer
;
FILE
*
f
;
FILE
*
f
;
f
=
fopen
(
name
,
"rb"
);
f
=
fopen
(
name
,
"rb"
);
if
(
!
f
)
if
(
!
f
)
return
0
;
return
0
;
*
buffer
=
NULL
;
buffer
=
NULL
;
if
(
max_size
&&
max_size
<
100
)
if
(
max_size
&&
max_size
<
100
)
size
=
max_size
;
size
=
max_size
;
...
@@ -75,22 +76,22 @@ read_file(const char *name, unsigned max_size, char **buffer)
...
@@ -75,22 +76,22 @@ read_file(const char *name, unsigned max_size, char **buffer)
{
{
char
*
p
;
char
*
p
;
if
(
size
>
max_size
)
if
(
max_size
&&
size
>
max_size
)
size
=
max_size
;
size
=
max_size
;
/* Space for terminating NUL */
/* Space for terminating NUL */
p
=
realloc
(
*
buffer
,
size
+
1
);
p
=
realloc
(
buffer
,
size
+
1
);
if
(
!
p
)
if
(
!
p
)
{
{
fail:
fail:
fclose
(
f
);
fclose
(
f
);
free
(
*
buffer
);
free
(
buffer
);
*
buffer
=
NULL
;
*
contents
=
NULL
;
return
0
;
return
0
;
}
}
*
buffer
=
p
;
buffer
=
p
;
done
+=
fread
(
buffer
+
done
,
1
,
size
-
done
,
f
);
done
+=
fread
(
buffer
+
done
,
1
,
size
-
done
,
f
);
if
(
ferror
(
f
))
if
(
ferror
(
f
))
...
@@ -100,7 +101,9 @@ read_file(const char *name, unsigned max_size, char **buffer)
...
@@ -100,7 +101,9 @@ read_file(const char *name, unsigned max_size, char **buffer)
fclose
(
f
);
fclose
(
f
);
/* NUL-terminate the data. */
/* NUL-terminate the data. */
(
*
buffer
)[
done
]
=
'\0'
;
buffer
[
done
]
=
'\0'
;
*
contents
=
buffer
;
return
done
;
return
done
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment