Patchwork [1,of,2] revlog: explicitly initialize static variables

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 9, 2018, 12:58 p.m.
Message ID <fec6a0498695298ec050.1539089931@mimosa>
Download mbox | patch
Permalink /patch/35576/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 9, 2018, 12:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1539038525 -32400
#      Tue Oct 09 07:42:05 2018 +0900
# Node ID fec6a0498695298ec0507a76cd26334794da93be
# Parent  8a08aefa9273e6f328f238e4793f9a43f314e471
revlog: explicitly initialize static variables

I know .bss section is zero-filled, but explicit initialization should be
better as we rely on that.
Gregory Szorc - Oct. 9, 2018, 3:06 p.m.
On Tue, Oct 9, 2018 at 6:00 AM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1539038525 -32400
> #      Tue Oct 09 07:42:05 2018 +0900
> # Node ID fec6a0498695298ec0507a76cd26334794da93be
> # Parent  8a08aefa9273e6f328f238e4793f9a43f314e471
> revlog: explicitly initialize static variables
>

Queued, thanks.


>
> I know .bss section is zero-filled, but explicit initialization should be
> better as we rely on that.
>
> diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
> --- a/mercurial/cext/revlog.c
> +++ b/mercurial/cext/revlog.c
> @@ -94,8 +94,8 @@ static Py_ssize_t index_length(const ind
>         return self->length + PyList_GET_SIZE(self->added);
>  }
>
> -static PyObject *nullentry;
> -static const char nullid[20];
> +static PyObject *nullentry = NULL;
> +static const char nullid[20] = {0};
>
>  static Py_ssize_t inline_scan(indexObject *self, const char **offsets);
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -94,8 +94,8 @@  static Py_ssize_t index_length(const ind
 	return self->length + PyList_GET_SIZE(self->added);
 }
 
-static PyObject *nullentry;
-static const char nullid[20];
+static PyObject *nullentry = NULL;
+static const char nullid[20] = {0};
 
 static Py_ssize_t inline_scan(indexObject *self, const char **offsets);