1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Merge pull request #12071 from Mic92/clang-tidy

Prepare nix to run with clang-tidy
This commit is contained in:
mergify[bot] 2024-12-17 21:53:35 +00:00 committed by GitHub
commit 3f3feae33e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 75 additions and 24 deletions

View file

@ -1,5 +1,13 @@
#pragma once #pragma once
#include <cstddef>
// inluding the generated headers twice leads to errors
#ifndef BISON_HEADER
# include "lexer-tab.hh"
# include "parser-tab.hh"
#endif
namespace nix::lexer::internal { namespace nix::lexer::internal {
void initLoc(YYLTYPE * loc); void initLoc(YYLTYPE * loc);

View file

@ -168,7 +168,7 @@ struct ExprVar : Expr
the set stored in the environment that is `level` levels up the set stored in the environment that is `level` levels up
from the current one.*/ from the current one.*/
Level level; Level level;
Displacement displ; Displacement displ = 0;
ExprVar(Symbol name) : name(name) { }; ExprVar(Symbol name) : name(name) { };
ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { }; ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { };
@ -242,7 +242,7 @@ struct ExprAttrs : Expr
Kind kind; Kind kind;
Expr * e; Expr * e;
PosIdx pos; PosIdx pos;
Displacement displ; // displacement Displacement displ = 0; // displacement
AttrDef(Expr * e, const PosIdx & pos, Kind kind = Kind::Plain) AttrDef(Expr * e, const PosIdx & pos, Kind kind = Kind::Plain)
: kind(kind), e(e), pos(pos) { }; : kind(kind), e(e), pos(pos) { };
AttrDef() { }; AttrDef() { };

View file

@ -5,6 +5,7 @@
*/ */
#include <limits> #include <limits>
#include <stddef.h>
namespace nix { namespace nix {

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
///@file ///@file
#include <string_view>
namespace nix { namespace nix {

View file

@ -2,10 +2,12 @@
#include "pathlocks.hh" #include "pathlocks.hh"
#include "signals.hh" #include "signals.hh"
#include "util.hh" #include "util.hh"
#include <errhandlingapi.h>
#include <fileapi.h> #ifdef WIN32
#include <windows.h> # include <errhandlingapi.h>
#include "windows-error.hh" # include <fileapi.h>
# include <windows.h>
# include "windows-error.hh"
namespace nix { namespace nix {
@ -154,3 +156,4 @@ FdLock::FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view w
} }
} }
#endif

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
///@file ///@file
#include <cassert>
#include <future> #include <future>
#include <functional> #include <functional>

View file

@ -13,6 +13,7 @@
*/ */
#include "config.hh" #include "config.hh"
#include "args.hh"
namespace nix { namespace nix {

View file

@ -2,6 +2,8 @@
///@file ///@file
#include <string_view> #include <string_view>
#include <string>
#include <sstream>
namespace nix::regex { namespace nix::regex {
@ -10,22 +12,23 @@ namespace nix::regex {
static inline std::string either(std::string_view a, std::string_view b) static inline std::string either(std::string_view a, std::string_view b)
{ {
return std::string { a } + "|" + b; std::stringstream ss;
ss << a << "|" << b;
return ss.str();
} }
static inline std::string group(std::string_view a) static inline std::string group(std::string_view a)
{ {
return std::string { "(" } + a + ")"; std::stringstream ss;
} ss << "(" << a << ")";
return ss.str();
static inline std::string many(std::string_view a)
{
return std::string { "(?:" } + a + ")*";
} }
static inline std::string list(std::string_view a) static inline std::string list(std::string_view a)
{ {
return std::string { a } + many(group("," + a)); std::stringstream ss;
ss << a << "(," << a << ")*";
return ss.str();
} }
} }

View file

@ -14,6 +14,7 @@
#include "error.hh" #include "error.hh"
#include "logging.hh" #include "logging.hh"
#include "ansicolor.hh" #include "ansicolor.hh"
#include "signals.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -1,6 +1,7 @@
#include "environment-variables.hh" #include "environment-variables.hh"
#include "processenv.h" #ifdef WIN32
# include "processenv.h"
namespace nix { namespace nix {
@ -43,3 +44,4 @@ int setEnvOs(const OsString & name, const OsString & value)
} }
} }
#endif

View file

@ -5,6 +5,7 @@
#include "windows-error.hh" #include "windows-error.hh"
#include "file-path.hh" #include "file-path.hh"
#ifdef WIN32
#include <fileapi.h> #include <fileapi.h>
#include <error.h> #include <error.h>
#include <namedpipeapi.h> #include <namedpipeapi.h>
@ -152,3 +153,4 @@ Path windows::handleToPath(HANDLE handle) {
#endif #endif
} }
#endif

View file

@ -1,5 +1,6 @@
#include "file-system.hh" #include "file-system.hh"
#ifdef WIN32
namespace nix { namespace nix {
Descriptor openDirectory(const std::filesystem::path & path) Descriptor openDirectory(const std::filesystem::path & path)
@ -15,3 +16,4 @@ Descriptor openDirectory(const std::filesystem::path & path)
} }
} }
#endif

View file

@ -1,9 +1,10 @@
#include <ioapiset.h> #ifdef WIN32
#include "windows-error.hh" # include <ioapiset.h>
# include "windows-error.hh"
#include "logging.hh" # include "logging.hh"
#include "util.hh" # include "util.hh"
#include "muxable-pipe.hh" # include "muxable-pipe.hh"
namespace nix { namespace nix {
@ -68,3 +69,4 @@ void MuxablePipePollState::iterate(
} }
} }
#endif

View file

@ -7,6 +7,8 @@
#include "file-path-impl.hh" #include "file-path-impl.hh"
#include "util.hh" #include "util.hh"
#ifdef WIN32
namespace nix { namespace nix {
std::string os_string_to_string(PathViewNG::string_view path) std::string os_string_to_string(PathViewNG::string_view path)
@ -22,3 +24,5 @@ std::filesystem::path::string_type string_to_os_string(std::string_view s)
} }
} }
#endif

View file

@ -23,6 +23,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -386,3 +388,5 @@ int execvpe(const wchar_t * file0, const wchar_t * const argv[], const wchar_t *
} }
} }
#endif

View file

@ -4,6 +4,7 @@
#include "file-system.hh" #include "file-system.hh"
#include "windows-error.hh" #include "windows-error.hh"
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -50,3 +51,4 @@ bool isRootUser() {
} }
} }
#endif

View file

@ -1,6 +1,8 @@
#include "windows-async-pipe.hh" #include "windows-async-pipe.hh"
#include "windows-error.hh" #include "windows-error.hh"
#ifdef WIN32
namespace nix::windows { namespace nix::windows {
void AsyncPipe::createAsyncPipe(HANDLE iocp) void AsyncPipe::createAsyncPipe(HANDLE iocp)
@ -47,3 +49,5 @@ void AsyncPipe::close()
} }
} }
#endif

View file

@ -2,6 +2,7 @@
///@file ///@file
#include "file-descriptor.hh" #include "file-descriptor.hh"
#ifdef WIN32
namespace nix::windows { namespace nix::windows {
@ -25,3 +26,4 @@ public:
}; };
} }
#endif

View file

@ -1,5 +1,6 @@
#include "windows-error.hh" #include "windows-error.hh"
#ifdef WIN32
#include <error.h> #include <error.h>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
@ -29,3 +30,4 @@ std::string WinError::renderError(DWORD lastError)
} }
} }
#endif

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
///@file ///@file
#ifdef WIN32
#include <errhandlingapi.h> #include <errhandlingapi.h>
#include "error.hh" #include "error.hh"
@ -49,3 +50,4 @@ private:
}; };
} }
#endif

View file

@ -2,6 +2,8 @@
///@file ///@file
#include <filesystem> #include <filesystem>
#include <optional>
#include <string_view>
namespace nix { namespace nix {

View file

@ -49,8 +49,8 @@ int main(int argc, char **argv) {
msg.msg_controllen = CMSG_SPACE(sizeof(int)); msg.msg_controllen = CMSG_SPACE(sizeof(int));
// Write a single null byte too. // Write a single null byte too.
msg.msg_iov = malloc(sizeof(struct iovec)); msg.msg_iov = (struct iovec*) malloc(sizeof(struct iovec));
msg.msg_iov[0].iov_base = ""; msg.msg_iov[0].iov_base = (void*) "";
msg.msg_iov[0].iov_len = 1; msg.msg_iov[0].iov_len = 1;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;

View file

@ -16,7 +16,7 @@ int main(int argc, char **argv) {
struct sockaddr_un data; struct sockaddr_un data;
data.sun_family = AF_UNIX; data.sun_family = AF_UNIX;
data.sun_path[0] = 0; data.sun_path[0] = 0;
strcpy(data.sun_path + 1, argv[1]); strncpy(data.sun_path + 1, argv[1], sizeof(data.sun_path) - 1);
int res = bind(sock, (const struct sockaddr *)&data, int res = bind(sock, (const struct sockaddr *)&data,
offsetof(struct sockaddr_un, sun_path) offsetof(struct sockaddr_un, sun_path)
+ strlen(argv[1]) + strlen(argv[1])
@ -57,10 +57,11 @@ int main(int argc, char **argv) {
// Wait for a second connection, which will tell us that the build is // Wait for a second connection, which will tell us that the build is
// done // done
a = accept(sock, 0, 0); a = accept(sock, 0, 0);
if (a < 0) perror("accept");
fprintf(stderr, "%s\n", "Got a second connection, rewriting the file"); fprintf(stderr, "%s\n", "Got a second connection, rewriting the file");
// Write a new content to the file // Write a new content to the file
if (ftruncate(smuggling_fd, 0)) perror("ftruncate"); if (ftruncate(smuggling_fd, 0)) perror("ftruncate");
char * new_content = "Pwned\n"; const char * new_content = "Pwned\n";
int written_bytes = write(smuggling_fd, new_content, strlen(new_content)); int written_bytes = write(smuggling_fd, new_content, strlen(new_content));
if (written_bytes != strlen(new_content)) perror("write"); if (written_bytes != strlen(new_content)) perror("write");
} }